From 5b42a88d0f3e1530c9aa664e35c0cf0e07a53bac Mon Sep 17 00:00:00 2001 From: Peace-Maker Date: Tue, 25 Oct 2022 16:55:35 +0200 Subject: [PATCH 1/2] Fix tube.recvpred() timout argument The `timeout` argument wasn't implemented correctly causing the function to hang instead of timing out. --- pwnlib/tubes/tube.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/pwnlib/tubes/tube.py b/pwnlib/tubes/tube.py index 54f68dcfb..037747d24 100644 --- a/pwnlib/tubes/tube.py +++ b/pwnlib/tubes/tube.py @@ -204,14 +204,29 @@ def recvpred(self, pred, timeout = default): Returns: A bytes object containing bytes received from the socket, or ``''`` if a timeout occurred while waiting. + + Examples: + + >>> t = tube() + >>> t.recv_raw = lambda n: b'abbbaccc' + >>> pred = lambda p: p.count(b'a') == 2 + >>> t.recvpred(pred) + b'abbba' + >>> pred = lambda p: p.count(b'd') > 0 + >>> t.recvpred(pred, timeout=0.05) + b'' """ data = b'' with self.countdown(timeout): while not pred(data): + if not self.countdown_active(): + self.unrecv(data) + return b'' + try: - res = self.recv(1) + res = self.recv(1, timeout=timeout) except Exception: self.unrecv(data) return b'' From 24fa08df638c268096c13218c858444da3fa8510 Mon Sep 17 00:00:00 2001 From: Peace-Maker Date: Tue, 25 Oct 2022 17:35:26 +0200 Subject: [PATCH 2/2] Update CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a6e8040f0..7b8fa9c87 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -95,12 +95,14 @@ The table below shows which release corresponds to each branch, and what date th - [#1939][1939] Fix error in validating log levels - [#1981][1981] Fix `cyclic_find()` to make it work with large int values - [#2123][2123] Fix ROP without a writeable cache directory +- [#2124][2124] Fix `tube.recvpred()` timout argument [1922]: https://github.com/Gallopsled/pwntools/pull/1922 [1828]: https://github.com/Gallopsled/pwntools/pull/1828 [1939]: https://github.com/Gallopsled/pwntools/pull/1939 [1981]: https://github.com/Gallopsled/pwntools/pull/1981 [2123]: https://github.com/Gallopsled/pwntools/pull/2123 +[2124]: https://github.com/Gallopsled/pwntools/pull/2124 ## 4.7.1