Skip to content

Commit

Permalink
Merge #21631: i2p: always check the return value of Sock::Wait()
Browse files Browse the repository at this point in the history
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
  • Loading branch information
MarcoFalke committed Apr 13, 2021
2 parents bd65a76 + 1c1467f commit 1f50f0b
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/i2p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ bool Session::Accept(Connection& conn)
try {
while (!*m_interrupt) {
Sock::Event occurred;
conn.sock->Wait(MAX_WAIT_FOR_IO, Sock::RECV, &occurred);
if (!conn.sock->Wait(MAX_WAIT_FOR_IO, Sock::RECV, &occurred)) {
throw std::runtime_error("wait on socket failed");
}

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

0 comments on commit 1f50f0b

Please sign in to comment.