dissect.target icon indicating copy to clipboard operation
dissect.target copied to clipboard

Linux images: ValueError: invalid literal for int() with base 10: 'None'

Open DissectBot opened this issue 1 year ago • 3 comments

Hello there!

I get this error quite often when I try to get information about linux images (e.g. ip adresses):

Traceback (most recent call last): File "/usr/local/bin/target-query", line 8, in sys.exit(main()) File "/usr/local/lib/python3.9/dist-packages/dissect/target/tools/utils.py", line 255, in wrapper return func(*args, **kwargs) File "/usr/local/lib/python3.9/dist-packages/dissect/target/tools/query.py", line 384, in main raise e File "/usr/local/lib/python3.9/dist-packages/dissect/target/tools/query.py", line 373, in main for record_entries in entry: File "/usr/local/lib/python3.9/dist-packages/dissect/target/plugins/general/osinfo.py", line 28, in osinfo value = getattr(self.target._os, os_func) File "/usr/local/lib/python3.9/dist-packages/dissect/target/helpers/cache.py", line 228, in cache_wrapper return cache.call(*args, **kwargs) File "/usr/local/lib/python3.9/dist-packages/dissect/target/helpers/cache.py", line 104, in call func_cache[key] = self.func(*args, **kwargs) File "/usr/local/lib/python3.9/dist-packages/dissect/target/plugins/os/unix/linux/_os.py", line 44, in ips for ip in parse_unix_dhcp_log_messages(self.target): File "/usr/local/lib/python3.9/dist-packages/dissect/target/helpers/network_managers.py", line 533, in parse_unix_dhcp_log_messages for record in messages: File "/usr/local/lib/python3.9/dist-packages/dissect/target/plugins/os/unix/log/journal.py", line 428, in journal uid=get_optional(entry.get("uid"), int), File "/usr/local/lib/python3.9/dist-packages/dissect/target/plugins/os/unix/log/journal.py", line 261, in get_optional return to_type(value) if value else None ValueError: invalid literal for int() with base 10: 'None'

Is there a way to fix this?

DissectBot avatar Jul 01 '24 12:07 DissectBot

Unable to reproduce, it is possible to get a sample file that contains this issue?

cecinestpasunepipe avatar Jul 09 '24 16:07 cecinestpasunepipe

I found the line in the journal, but I can't share. The issue was caused by a line created by ansible, where the uid is set to the word "None".

Dissect tries to parse this to an Integer. The check in "/usr/local/lib/python3.9/dist-packages/dissect/target/plugins/os/unix/log/journal.py" line 261 checks if the variable is None, but not if the contained string is 'None'.

An easy fix would be to check if the value is the string None. Tried this and it worked: return to_type(value) if value and value != 'None' else None

h0ckeyst1ck avatar Jul 12 '24 12:07 h0ckeyst1ck

okay, just let's add a comment then to clarify okay, for the rest your patch looks good.

cecinestpasunepipe avatar Jul 16 '24 11:07 cecinestpasunepipe