Skip to content

Commit 1f50f0b

Browse files
author
MarcoFalke
committed
Merge #21631: i2p: always check the return value of Sock::Wait()
1c1467f i2p: cancel the Accept() method if waiting on the socket errors (Vasil Dimov) Pull request description: If `Sock::Wait()` fails, then cancel the `Accept()` method. Not checking the return value may cause an uninitialized read a few lines below when we read the `occurred` variable. [Spotted](bitcoin/bitcoin#21630 (comment)) by MarcoFalke, thanks! ACKs for top commit: laanwj: Code review ACK 1c1467f practicalswift: cr ACK 1c1467f: patch looks correct and agree with laanwj that `[[nodiscard]]` can be taken in a follow-up PR :) Tree-SHA512: 57fa8a03a4e055999e23121cd9ed1566a585ece0cf68b74223d8c902804cb6890218c9356d60e0560ccacc6c8542a526356c226ebd48e7b299b4572be312d49b
2 parents bd65a76 + 1c1467f commit 1f50f0b

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/i2p.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,9 @@ bool Session::Accept(Connection& conn)
147147
try {
148148
while (!*m_interrupt) {
149149
Sock::Event occurred;
150-
conn.sock->Wait(MAX_WAIT_FOR_IO, Sock::RECV, &occurred);
150+
if (!conn.sock->Wait(MAX_WAIT_FOR_IO, Sock::RECV, &occurred)) {
151+
throw std::runtime_error("wait on socket failed");
152+
}
151153

152154
if ((occurred & Sock::RECV) == 0) {
153155
// Timeout, no incoming connections within MAX_WAIT_FOR_IO.

0 commit comments

Comments
 (0)