Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
DissectBot opened this issue Jul 1, 2024 · 3 comments · May be fixed by #746
Open

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

DissectBot opened this issue Jul 1, 2024 · 3 comments · May be fixed by #746
Assignees
Labels
bug Something isn't working

Comments

@DissectBot
Copy link

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?

@cecinestpasunepipe
Copy link
Contributor

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

@h0ckeyst1ck
Copy link

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 h0ckeyst1ck linked a pull request Jul 12, 2024 that will close this issue
@cecinestpasunepipe
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants