From 3ba5c1555f1fdfd9d69f3ffe991aab48c2144aa9 Mon Sep 17 00:00:00 2001 From: Squirre17 <79578430+Squirre17@users.noreply.github.com> Date: Mon, 3 Apr 2023 02:50:43 +0800 Subject: [PATCH] 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 --- pwndbg/arguments.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pwndbg/arguments.py b/pwndbg/arguments.py index cedebae52..030a47a61 100644 --- a/pwndbg/arguments.py +++ b/pwndbg/arguments.py @@ -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