pwntools
pwntools copied to clipboard
Process: Fix AttributeError when stdin, stdout, and stderr are redirected to files
This closes #2036.
This PR would allow users to redirect stdin
, stdout
, or/and stderr
to files via 2 methods, even partially (i.e., the user can choose to redirect only stdin
, only stdout
, only stderr
, or any combination of those 3):
-
By using Python's built-in
open()
function:pwn.process("cat", stdin=open("some_file", "r"), stdout=open("some_other_file", "w"), stderr=open("yet_another_file", "w"))
-
By using the
os.open()
function:pwn.process(["cat", "-"], stdin=os.open("some_file", os.O_RDWR), stdout=os.open("some_other_file", os.O_RDWR), stderr=os.open("yet_another_file", os.O_RDWR))
If the user passes in some raw integer(s) for stdin
, stdout
, or/and stderr
, such as when they invoke os.open()
, we only attempt to check whether they are valid file descriptors or not. Other than that, we trust the user that they know what they are doing.
@Arusekk Could you kindly review this PR? Thank you!
It looks like this code is overly complex. I think we do not want to do any file descriptor validation, as they are foreign objects to Python code, and validating them is inherently racy.