Gallopsled / pwntools

CTF framework and exploit development library
http://pwntools.com
Other
11.69k stars 1.67k forks source link

`CorefileFinder.read` returns bytes instead of str type #2386

Closed marinelay closed 1 month ago

marinelay commented 2 months ago

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

https://github.com/Gallopsled/pwntools/blob/5981c7290dd5190733c1f2e9ccf08633869f8b31/pwnlib/elf/corefile.py#L1309-L1332

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 commented 2 months ago

https://github.com/Gallopsled/pwntools/pull/2387