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

CorefileFinder.read returns bytes instead of str type #2386

Closed
marinelay opened this issue Apr 11, 2024 · 1 comment · Fixed by #2387
Closed

CorefileFinder.read returns bytes instead of str type #2386

marinelay opened this issue Apr 11, 2024 · 1 comment · Fixed by #2387

Comments

@marinelay
Copy link
Contributor

Create test.py like:

from pwnlib.tubes.process import process
from pwnlib.elf.corefile import CorefileFinder

p = process('cat')
p.shutdown('send')
p.wait_for_close()

c = CorefileFinder(p)
c.apport_corefile()

then it raises TypeError: initial_value must be str or None, not bytes like this:

Traceback (most recent call last):
  File "/home/wonseok/current/pwntools/my_test.py", line 7, in <module>
    c = CorefileFinder(p)
  File "/home/wonseok/current/pwntools/pwnlib/elf/corefile.py", line 1197, in __init__
    self.core_path = self.native_corefile()
  File "/home/wonseok/current/pwntools/pwnlib/elf/corefile.py", line 1372, in native_corefile
    return self.native_corefile_pipe()
  File "/home/wonseok/current/pwntools/pwnlib/elf/corefile.py", line 1390, in native_corefile_pipe
    apport_core = self.apport_corefile()
  File "/home/wonseok/current/pwntools/pwnlib/elf/corefile.py", line 1262, in apport_corefile
    return self.apport_crash_extract_corefile(crash_data)
  File "/home/wonseok/current/pwntools/pwnlib/elf/corefile.py", line 1273, in apport_crash_extract_corefile
    file = StringIO(crashfile_data)
TypeError: initial_value must be str or None, not bytes

def apport_read_crash_data(self):
"""Find the apport crash for the process
Returns:
`str`: Raw contents of the crash file or ``None``.
"""
uid = self.uid
crash_name = self.exe.replace('/', '_')
crash_path = '/var/crash/%s.%i.crash' % (crash_name, uid)
try:
log.debug("Looking for Apport crash at %r" % crash_path)
data = self.read(crash_path)
except Exception:
return None
# Remove the crash file, so that future crashes will be captured
try:
self.unlink(crash_path)
except Exception:
pass
return data

The cause is that apport_read_crash_data method returns bytes because self.read at line 1322 can return bytes instead of str.
I think that type casting can be solution before return statement.
If I missed something, please let me know.

Thank you.

@sanjitkumar2016
Copy link
Contributor

#2387

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants