snovvcrash / usbrip

Tracking history of USB events on GNU/Linux
https://habr.com/ru/post/352254/
GNU General Public License v3.0
1.15k stars 112 forks source link

AttributeError: 'NoneType' #6

Closed scaery closed 5 years ago

scaery commented 5 years ago

What issue is causing this?


[*] Started at 2019-07-29 20:59:51
[20:59:51] [INFO] Searching for log files: "/var/log/syslog*" or "/var/log/messages*"
[20:59:51] [INFO] Reading "/var/log/syslog"
[21:00:02] [INFO] Reading "/var/log/syslog.1"
[21:00:02] [INFO] Unpacking "/var/log/syslog.2.gz"
[21:00:02] [INFO] Reading "/var/log/syslog.2"
[21:00:02] [INFO] Unpacking "/var/log/syslog.3.gz"
[21:00:02] [INFO] Reading "/var/log/syslog.3"
[21:00:03] [INFO] Unpacking "/var/log/syslog.4.gz"
[21:00:03] [INFO] Reading "/var/log/syslog.4"
[21:00:03] [INFO] Unpacking "/var/log/syslog.5.gz"
[21:00:03] [INFO] Reading "/var/log/syslog.5"
[21:00:03] [INFO] Unpacking "/var/log/syslog.6.gz"
[21:00:03] [INFO] Reading "/var/log/syslog.6"
[21:00:03] [INFO] Unpacking "/var/log/syslog.7.gz"
[21:00:03] [INFO] Reading "/var/log/syslog.7"
Traceback (most recent call last):
  File "/usr/local/bin/usbrip", line 11, in <module>
    load_entry_point('usbrip==2.1.3.post2', 'console_scripts', 'usbrip')()
  File "/usr/local/lib/python3.7/dist-packages/usbrip/__main__.py", line 88, in main
    ueh = USBEvents(args.file)
  File "/usr/local/lib/python3.7/dist-packages/usbrip/lib/core/usbevents.py", line 93, in __new__
    all_events = _parse_history(divided_history)
  File "/usr/local/lib/python3.7/dist-packages/usbrip/lib/core/usbevents.py", line 409, in _parse_history
    port = re_port.search(line).group(1)
AttributeError: 'NoneType' object has no attribute 'group'
[*] Shutted down at 2019-07-29 21:00:03
[*] Time taken: 0:00:12.101668

A small change did the trick: remove ".group()1" Edit 409: port = re_port.search(line) #.group(1)

snovvcrash commented 5 years ago

Could you provide the OS distribution name and do some debugging for me, pls? In order not to ask you for the whole syslog file, just output the line where the regex crashes by wrapping this fragment in usbevents.py in try-except-else block like this:

...
if 'disconnect' in line:
    try:
        port = re_port.search(line).group(1)
    except AttributeError:
        print(f'DEBUG: {line}')
    else:
        for i in range(len(all_events)-1, -1, -1):
            if all_events[i]['port'] == port:
                all_events[i]['disconn'] = date
                break
...

Rerun the events history command and show me this line, please.

scaery commented 5 years ago

Thank you for the quick response and for your time, this is what i got:

DEBUG: Aug 25 15:31:19 kali kernel: [ 4839.627427] dvb_usb_v2: 'TerraTec Cinergy T Stick RC (Rev. 3):1-2' successfully deinitialized and disconnected

snovvcrash commented 5 years ago

Thanks for the feedback! Not sure why this syslog message was generated that way. I guess the usb port part is just missing, as for me it should look like this (port number is rnd):

Aug 25 15:31:19 kali kernel: [ 4839.627427] usb 1-5: dvb_usb_v2: 'TerraTec Cinergy T Stick RC (Rev. 3):1-2' successfully deinitialized and disconnected

Nevertheless, I've updated the tool with some extra try-except wrapping for now. Will examine this case more precisely when I have time.