pkgsrc-WIP-changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

py-pwntools: Add a kludge to fix pwn.process()



Module Name:	pkgsrc-wip
Committed By:	Leonardo Taccari <iamleot%gmail.com@localhost>
Pushed By:	leot
Date:		Mon Apr 21 16:25:49 2025 +0200
Changeset:	ad84ce90ec5dd3e9df11014c16f887088ffcb131

Modified Files:
	py-pwntools/distinfo
Added Files:
	py-pwntools/patches/patch-pwnlib_tubes_process.py

Log Message:
py-pwntools: Add a kludge to fix pwn.process()

Avoid to invoke to set internal_preexec_fn in NetBSD because otherwise
it fails and pwn.process() is not usable.

Add a big XXX: comment in the patch and a reproducer.

(The logic was not present in (much) older pwntools.)

This should be investigated better and fixed properly.

To see a diff of this commit:
https://wip.pkgsrc.org/cgi-bin/gitweb.cgi?p=pkgsrc-wip.git;a=commitdiff;h=ad84ce90ec5dd3e9df11014c16f887088ffcb131

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

diffstat:
 py-pwntools/distinfo                              |  1 +
 py-pwntools/patches/patch-pwnlib_tubes_process.py | 48 +++++++++++++++++++++++
 2 files changed, 49 insertions(+)

diffs:
diff --git a/py-pwntools/distinfo b/py-pwntools/distinfo
index eb714fbbb5..201423da9e 100644
--- a/py-pwntools/distinfo
+++ b/py-pwntools/distinfo
@@ -3,3 +3,4 @@ $NetBSD$
 BLAKE2s (pwntools-4.13.1.tar.gz) = 5f8183b17b825c518f5ee8adadce91f11a16efba6a1d696311d97941d2ca8b16
 SHA512 (pwntools-4.13.1.tar.gz) = cd4c9e13c27ab5343f0b1c26b03bf0e59dc755ede1ee0d1d2dc4f7a895c5474cefb0d03f581a6ad1b5f573ddd54134d0a9db63a7db6c8a44f2d229fb80f1fe9f
 Size (pwntools-4.13.1.tar.gz) = 5476226 bytes
+SHA1 (patch-pwnlib_tubes_process.py) = a37ab820ba954d638b374752d38c51b737d6cb44
diff --git a/py-pwntools/patches/patch-pwnlib_tubes_process.py b/py-pwntools/patches/patch-pwnlib_tubes_process.py
new file mode 100644
index 0000000000..8e9169d3de
--- /dev/null
+++ b/py-pwntools/patches/patch-pwnlib_tubes_process.py
@@ -0,0 +1,48 @@
+$NetBSD$
+
+Avoid to invoke preexec_fn on NetBSD.
+
+It fails due some exception.
+
+Easily reproducible via:
+
+ python3 -c 'import pwn; pwn.process("true")'
+
+--- pwnlib/tubes/process.py.orig	2025-04-21 14:06:00.563442247 +0000
++++ pwnlib/tubes/process.py
+@@ -13,6 +13,7 @@ import subprocess
+ import sys
+ import time
+ 
++IS_NETBSD = sys.platform.startswith('netbsd')
+ IS_WINDOWS = sys.platform.startswith('win')
+ 
+ if IS_WINDOWS:
+@@ -306,7 +307,26 @@ class process(tube):
+             # Create the PTY if necessary
+             stdin, stdout, stderr, master, slave = self._handles(*handles)
+ 
+-            internal_preexec_fn = self.__preexec_fn
++            if IS_NETBSD:
++                # XXX: On NetBSD running
++                # XXX:  `python3 -c 'import pwn; pwn.process("true")'`
++                # XXX: Fails with:
++                # XXX: [-] Starting local process '/usr/bin/true': Failed
++                # XXX: Traceback (most recent call last):
++                # XXX:   File "<string>", line 1, in <module>
++                # XXX:   File "/usr/pkg/lib/python3.12/site-packages/pwnlib/tubes/process.py", line 359, in __init__
++                # XXX:     self.proc = subprocess.Popen(args = args,
++                # XXX:                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
++                # XXX:   File "/usr/pkg/lib/python3.12/subprocess.py", line 1026, in __init__
++                # XXX:     self._execute_child(args, executable, preexec_fn, close_fds,
++                # XXX:   File "/usr/pkg/lib/python3.12/subprocess.py", line 1958, in _execute_child
++                # XXX:     raise child_exception_type(err_msg)
++                # XXX: subprocess.SubprocessError: Exception occurred in preexec_fn.
++                # XXX: Avoid to use the self.__preexec_fn completely.
++                # XXX: This should be investigated and addressed properly!
++                internal_preexec_fn = None
++            else:
++                internal_preexec_fn = self.__preexec_fn
+ 
+         #: Arguments passed on argv
+         self.argv = argv_val


Home | Main Index | Thread Index | Old Index