Fixed a crash that caused formatting failure in readlink when qemu returns None as the pid. (#1644)

* Fixed a crash that caused formatting failure in readlink when qemu returns None as the pid.

* Formated code

* Update pwndbg/arguments.py

* Assign a pid prevent repetitive calls.

* Format it

* remove the warning

* add a comment about the senario that PID is None in qemu

---------

Co-authored-by: Disconnect3d <dominik.b.czarnota@gmail.com>
pull/1659/head
Squirre17 3 years ago committed by GitHub
parent c02f18e227
commit 3ba5c1555f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -221,9 +221,12 @@ def format_args(instruction):
# Enhance args display
if arg.name == "fd" and isinstance(value, int):
path = pwndbg.gdblib.file.readlink("/proc/%d/fd/%d" % (pwndbg.gdblib.proc.pid, value))
if path:
pretty += " (%s)" % path
# Cannot find PID of the QEMU program: perhaps it is in a different pid namespace or we have no permission to read the QEMU process' /proc/$pid/fd/$fd file.
pid = pwndbg.gdblib.proc.pid
if pid is not None:
path = pwndbg.gdblib.file.readlink("/proc/%d/fd/%d" % (pid, value))
if path:
pretty += " (%s)" % path
result.append("%-10s %s" % (N.argument(arg.name) + ":", pretty))
return result

Loading…
Cancel
Save