From 14bb546efede30c6f2e7ef7ea65cedf561987da2 Mon Sep 17 00:00:00 2001 From: Unknown Sentinel <63234449+Unknownsentinel193@users.noreply.github.com> Date: Sun, 14 May 2023 22:56:37 +0530 Subject: [PATCH] Fix test command procinfo (#1706) * Updated canary.py for better display * Updated test_command_procinfo.py * Revert "Updated canary.py for better display" This reverts commit 802e243183aa87c851f9e180695c3fe40c7dd362. * Fix lint issue * Update test_command_procinfo.py --------- Co-authored-by: Unknown6334 <63234449+Unknown1934-del@users.noreply.github.com> Co-authored-by: Disconnect3d --- .../gdb-tests/tests/test_command_procinfo.py | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/tests/gdb-tests/tests/test_command_procinfo.py b/tests/gdb-tests/tests/test_command_procinfo.py index 02c61a47e..074d7ea81 100644 --- a/tests/gdb-tests/tests/test_command_procinfo.py +++ b/tests/gdb-tests/tests/test_command_procinfo.py @@ -1,5 +1,7 @@ import os import shutil +import signal +import subprocess import gdb @@ -11,9 +13,18 @@ REFERENCE_BINARY_NET = tests.binaries.get("reference-binary-net.out") def test_command_procinfo(start_binary): start_binary(REFERENCE_BINARY_NET) - # Sanity check, netcat must exist at this point - assert shutil.which("nc") is not None - os.system("nc -l -p 31337 2>/dev/null 1>&2 &") + # Check if netcat exists + nc_path = shutil.which("nc") + assert nc_path is not None, "netcat is not installed" + + # Spawn netcat + netcat_process = subprocess.Popen( + [nc_path, "-l", "-p", "31337"], + stdin=subprocess.DEVNULL, + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL, + start_new_session=True, + ) bin_path = gdb.execute("pi pwndbg.gdblib.proc.exe", to_string=True).strip("\n") pid = gdb.execute("pi pwndbg.gdblib.proc.pid", to_string=True).strip("\n") @@ -28,6 +39,9 @@ def test_command_procinfo(start_binary): assert pid in res_list[1] assert "127.0.0.1:31337" in result + # Close netcat + os.killpg(os.getpgid(netcat_process.pid), signal.SIGTERM) + def test_command_procinfo_before_binary_start(): result = gdb.execute("procinfo", to_string=True)