From 7abeef65605da22695d2ea9f321e5dbaf79e5395 Mon Sep 17 00:00:00 2001 From: smiley Date: Thu, 17 Aug 2023 15:29:37 +0100 Subject: [PATCH] fix embedded null in cmdline string --- pwndbg/commands/procinfo.py | 5 +++-- tests/gdb-tests/tests/test_command_procinfo.py | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pwndbg/commands/procinfo.py b/pwndbg/commands/procinfo.py index f1305536a..9b995331c 100644 --- a/pwndbg/commands/procinfo.py +++ b/pwndbg/commands/procinfo.py @@ -87,7 +87,8 @@ class Process: @pwndbg.lib.cache.cache_until("stop") def cmdline(self): raw = pwndbg.gdblib.file.get(f"/proc/{self.pid}/cmdline") - return f"'{raw.decode()}'" + cmdline = raw.decode().rstrip("\x00").strip() + return f"'{cmdline}'" @property @pwndbg.lib.cache.cache_until("stop") @@ -223,7 +224,7 @@ def procinfo() -> None: if not proc.status: return - # print("%-10s %s" % ("cmdline", proc.something)) + print("%-10s %s" % ("cmdline", proc.cmdline)) print("%-10s %s" % ("cwd", proc.cwd)) diff --git a/tests/gdb-tests/tests/test_command_procinfo.py b/tests/gdb-tests/tests/test_command_procinfo.py index 9935d75c9..a30ef29ae 100644 --- a/tests/gdb-tests/tests/test_command_procinfo.py +++ b/tests/gdb-tests/tests/test_command_procinfo.py @@ -38,7 +38,7 @@ def test_command_procinfo(start_binary): res_list = result.split("\n") assert bin_path in res_list[0] - assert pid in res_list[2] + assert pid in res_list[3] assert "127.0.0.1:31337" in result # Close netcat