Skip to content

Commit

Permalink
Raise EOFError during process.recv when stdout closes on Windows (#2524)
Browse files Browse the repository at this point in the history
* Windows: Raise EOFError during process.recv when stdout closes

If the receiving thread terminates while we're waiting for data to arrive we'd be waiting endlessly. Raise EOFError when .recv()ing on a process with stdout closed and no more data queued up from the receiver thread.

* Update CHANGELOG
  • Loading branch information
peace-maker authored Jan 21, 2025
1 parent fac8f1e commit a9b05b5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,11 @@ The table below shows which release corresponds to each branch, and what date th

- [#2507][2507] Add `+LINUX` and `+WINDOWS` doctest options and start proper testing on Windows
- [#2522][2522] Support starting a kitty debugging window with the 'kitten' command
- [#2524][2524] Raise EOFError during `process.recv` when stdout closes on Windows

[2507]: https://github.com/Gallopsled/pwntools/pull/2507
[2522]: https://github.com/Gallopsled/pwntools/pull/2522
[2524]: https://github.com/Gallopsled/pwntools/pull/2524

## 4.15.0 (`beta`)
- [#2508][2508] Ignore a warning when compiling with asm on nix
Expand Down
8 changes: 6 additions & 2 deletions pwnlib/tubes/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -767,9 +767,13 @@ def can_recv_raw(self, timeout):

if IS_WINDOWS:
with self.countdown(timeout=timeout):
while self.timeout and self._read_queue.empty():
while self.timeout and self._read_queue.empty() and self._read_thread.is_alive():
time.sleep(0.01)
return not self._read_queue.empty()
if not self._read_queue.empty():
return True
if not self._read_thread.is_alive():
raise EOFError
return False

try:
if timeout is None:
Expand Down

0 comments on commit a9b05b5

Please sign in to comment.