schollz / find3-cli-scanner

The command-line scanner that supports Bluetooth and WiFi
https://www.internalpositioning.com/doc/tracking_your_computer.md
148 stars 55 forks source link

panic: runtime error: index out of range #8

Closed hit0ri closed 6 years ago

hit0ri commented 6 years ago

Hi. I'm experiencing frequent panics in ReverseScan function

$ t ~ sudo find3-cli-scanner -i wlp2s0mon -device scanner -family foobar -server http://xxx.xxx.x.xxx:8005 -scantime 40 -forever -passive -no-modify -debug
2018-04-05 16:00:16 [INFO] main.go main:79 reverse scanning with wlp2s0mon
2018-04-05 16:00:16 [DEBUG] reverse.go ReverseScan:35 saving tshark data to /tmp/tshark-EEwElGdpxR
2018-04-05 16:00:16 [DEBUG] reverse.go ReverseScan:36 tshark -I -i wlp2s0mon -a duration:40 -w /tmp/tshark-EEwElGdpxR
2018-04-05 16:00:16 [DEBUG] utils.go RunCommand:15 tshark -I -i wlp2s0mon -a duration:40 -w /tmp/tshark-EEwElGdpxR
2018-04-05 16:00:57 [DEBUG] utils.go RunCommand:39 tshark -I -i wlp2s0mon -a duration:40 -w /tmp/tshark-EEwElGdpxR done gracefully without error
2018-04-05 16:00:57 [DEBUG] utils.go RunCommand:15 /usr/bin/tshark -r /tmp/tshark-EEwElGdpxR -T fields -e frame.time_epoch -e wlan.ta -e wlan.ra -e radiotap.dbm_antsignal
2018-04-05 16:00:57 [DEBUG] utils.go RunCommand:39 /usr/bin/tshark -r /tmp/tshark-EEwElGdpxR -T fields -e frame.time_epoch -e wlan.ta -e wlan.ra -e radiotap.dbm_antsignal done gracefully without error
panic: runtime error: index out of range

goroutine 1 [running]:
main.ReverseScan(0x9502f9000, 0x16295e4b376, 0x7ffc8f94b3a5, 0x6, 0x7ffc8f94b395, 0x7, 0x0, 0x0, 0xc42007b9b0, 0x0, ...)
        /home/hitori/go/src/github.com/schollz/find3-cli-scanner/reverse.go:75 +0x18b0
main.reverseCapture()
        /home/hitori/go/src/github.com/schollz/find3-cli-scanner/main.go:98 +0xbb
main.main()
        /home/hitori/go/src/github.com/schollz/find3-cli-scanner/main.go:79 +0x4bd

Here's the example output of tshark that is causing a crash:

1522933949.290066078    00:00:00:00:52:78   ff:ff:ff:ff:ff:ff   -49,-49,-49
1522933949.439473026    00:00:00:00:52:78   ff:ff:ff:ff:ff:ff   -50,-50,-50
1522933949.452939537    00:00:00:00:52:78   ff:ff:ff:ff:ff:ff   -49,-49,-49
1522933949.459568631        00:00:00:00:0d:70   -50,-50,-50
1522933949.787056388    00:00:00:00:b0:64   ff:ff:ff:ff:ff:ff   -62,-62,-64
1522933949.953996842    00:00:00:00:57:f5   ff:ff:ff:ff:ff:ff   -52,-54,-52
1522933949.959195300    00:00:00:00:57:f5   ff:ff:ff:ff:ff:ff   -51,-53,-51
1522933949.974215793    00:00:00:00:57:f5   ff:ff:ff:ff:ff:ff   -48,-52,-48
1522933949.976558659    00:00:00:00:57:f5   ff:ff:ff:ff:ff:ff   -47,-50,-47
1522933949.996458237    00:00:00:00:57:f5   ff:ff:ff:ff:ff:ff   -50,-54,-50
1522933950.669809125    00:00:00:00:1e:d2   ff:ff:ff:ff:ff:ff   -64,-64,-65
1522933950.694347246    00:00:00:00:1e:d2   ff:ff:ff:ff:ff:ff   -59,-59,-62
1522933950.747135532    00:00:00:00:4b:ff   ff:ff:ff:ff:ff:ff   -66,-67,-66
1522933961.174288320    00:00:00:00:d8:77   ff:ff:ff:ff:ff:ff   -54,-54,-59
1522933961.185383139        00:00:00:00:ee:d6   -52,-52,-58
1522933961.192651386    00:00:00:00:d8:77   ff:ff:ff:ff:ff:ff   -52,-52,-58
1522933961.196418575        00:00:00:00:ee:d6   -54,-54,-59
1522933961.199881394    00:00:00:00:d8:77   ff:ff:ff:ff:ff:ff   -53,-53,-58
1522933961.203358944    00:00:00:00:ee:d6   00:00:00:00:d8:77   -73,-73,-84
1522933961.203653771        00:00:00:00:ee:d6   -54,-54,-59
1522933961.229108531    00:00:00:00:d8:77   ff:ff:ff:ff:ff:ff   -51,-51,-58
1522933961.237570373    00:00:00:00:d8:77   ff:ff:ff:ff:ff:ff   -49,-49,-56
1522933961.247386576    00:00:00:00:d8:77   ff:ff:ff:ff:ff:ff   -49,-49,-56
1522933961.257661756    00:00:00:00:d8:77   ff:ff:ff:ff:ff:ff   -53,-53,-63
1522933961.266957244    00:00:00:00:d8:77   ff:ff:ff:ff:ff:ff   -51,-51,-61
1522933961.277250665    00:00:00:00:d8:77   ff:ff:ff:ff:ff:ff   -52,-52,-61
1522933965.589258081    00:00:00:00:ee:d6   ff:ff:ff:ff:ff:ff   -73,-73,-80
1522933965.693361514    00:00:00:00:2e:38   ff:ff:ff:ff:ff:ff   -57,-57,-65
1522933965.696845552    00:00:00:00:ee:d6   00:00:00:00:2e:38   -72,-72,-78
1522933965.725199920    00:00:00:00:2e:38   ff:ff:ff:ff:ff:ff   -55,-55,-65
1522933967.181482941    00:00:00:00:1a:08   ff:ff:ff:ff:ff:ff   -65,-65,-68
1522933967.190208835    00:00:00:00:a0:f5   00:00:00:00:1a:08   -64,-65,-64
1522933967.351161755    00:00:00:00:1a:08   ff:ff:ff:ff:ff:ff   -66,-66,-69
1522933967.354155548        00:00:00:00:22:6f   -65,-65,-68
1522933967.368812628        00:00:00:00:0d:70   -65,-65,-71
1522933969.574723359        00:00:00:00:22:6f   -62,-62,-82
1522933969.635361181        00:00:00:00:61:49   -59,-59,-70
1522933969.639868085    00:00:00:00:61:49   ff:ff:ff:ff:ff:ff   -59,-59,-74
1522933969.642818065        00:00:00:00:a0:f5   -60,-60,-73
1522933969.645128578        00:00:00:00:a0:f5   -63,-63,-75
1522933969.660195755    00:00:00:00:61:49   ff:ff:ff:ff:ff:ff   -61,-61,-76
1522933969.684261668    00:00:00:00:61:49   ff:ff:ff:ff:ff:ff   -62,-62,-77
1522933970.194807561    00:00:00:00:e5:d0   ff:ff:ff:ff:ff:ff   -66,-66,-67
1522933970.201373817        00:00:00:00:ee:d6   -65,-65,-66
1522933970.223421346    00:00:00:00:e5:d0   ff:ff:ff:ff:ff:ff   -63,-64,-63
1522933970.251950891    00:00:00:00:e5:d0   ff:ff:ff:ff:ff:ff   -68,-70,-68
1522933972.887942551        00:00:00:00:22:6f   -57,-57,-66
1522933972.901310557    00:00:00:00:ce:64   ff:ff:ff:ff:ff:ff   -56,-56,-67
1522933972.920757665        00:00:00:00:ce:64   -58,-58,-66
1522933972.924853703    00:00:00:00:ce:64   ff:ff:ff:ff:ff:ff   -54,-54,-62
1522933972.944867075    00:00:00:00:ce:64   ff:ff:ff:ff:ff:ff   -55,-55,-63
1522933976.853702725    00:00:00:00:ee:d6   ff:ff:ff:ff:ff:ff   -74,-74,-86
1522933981.154875417    00:00:00:00:ee:d6   ff:ff:ff:ff:ff:ff   -75,-75,-77

System info: go version go1.9.4 linux/amd64 find3-cli-scanner version: cc70e6a TShark (Wireshark) 2.4.5 (v2.4.5) Network controller: Intel Corporation Wireless 7260 (rev 73)

schollz commented 6 years ago

Thanks, I made a change to fix it

hit0ri commented 6 years ago

Commit e11dc1a did not fixed it, still crashing for me. But after I modified the if statement below it works fine.

diff --git a/reverse.go b/reverse.go
index b893fe8..e816cdc 100644
--- a/reverse.go
+++ b/reverse.go
@@ -72,7 +72,7 @@ func ReverseScan(scanTime time.Duration) (sensors models.SensorData, err error)
                                continue
                        }
                        packet.RSSI = int(rssi)
-                       if i > len(packets) {
+                       if i >= len(packets) {
                                packets = append(packets, packet)
                        } else {
                                packets[i] = packet
hit0ri commented 6 years ago

Should I open a new issue?

angian00 commented 6 years ago

Having a similar (same?) problem with v3.3.2-1-gd1eb4ef.


2018-09-17 15:46:19 [INFO] main.go func1:222 working in passive mode 
panic: runtime error: index out of range

goroutine 1 [running]:
main.ReverseScan(0x2a05f200, 0x1, 0xe836052f, 0x165, 0x7ea08768, 0x9, 0x7ea08755
, 0xa, 0x0, 0x0, ...)
    /home/zns/code/find3-cli-scanner/reverse.go:119 +0xb20
main.reverseCapture(0x2b4e4c0, 0x1)
    /home/zns/code/find3-cli-scanner/main.go:257 +0x558
main.main.func1(0x18b0210, 0x18b0210, 0x18c9bec)
    /home/zns/code/find3-cli-scanner/main.go:222 +0x538
github.com/urfave/cli.HandleAction(0x3bb448, 0x45bdf0, 0x18b0210, 0x188e2a0, 0x0
)
    /home/zns/go/pkg/mod/github.com/urfave/cli@v1.20.0/app.go:490 +0xac
github.com/urfave/cli.(*App).Run(0x1800ee0, 0x1816150, 0xe, 0xe, 0x0, 0x0)
    /home/zns/go/pkg/mod/github.com/urfave/cli@v1.20.0/app.go:264 +0x3f0
main.main()
    /home/zns/code/find3-cli-scanner/main.go:232 +0x920
schollz commented 6 years ago

I pushed a fix for this I believe

angian00 commented 6 years ago

Indeed the tool seems stable now, active for two days without crashes. Thanks for the prompt response.