Skip to content

Commit

Permalink
Fix recursion bug on write error
Browse files Browse the repository at this point in the history
Depending on the stack size, too many clients on the same channel
quitting at the same time would trigger a crash due to too many
recursive calls to Conn_Close().
  • Loading branch information
michi authored and alexbarton committed Apr 19, 2020
1 parent 13b8324 commit 04de142
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/ngircd/conn.c
Expand Up @@ -1272,14 +1272,17 @@ Handle_Write( CONN_ID Idx )
if (errno == EAGAIN || errno == EINTR)
return true;

/* Log write errors but do not close the connection yet.
* Calling Conn_Close() now could result in too many recursive calls.
*/
if (!Conn_OPTION_ISSET(&My_Connections[Idx], CONN_ISCLOSING))
Log(LOG_ERR,
"Write error on connection %d (socket %d): %s!",
Idx, My_Connections[Idx].sock, strerror(errno));
else
LogDebug("Recursive write error on connection %d (socket %d): %s!",
Idx, My_Connections[Idx].sock, strerror(errno));
Conn_Close(Idx, "Write error", NULL, false);

return false;
}

Expand Down

0 comments on commit 04de142

Please sign in to comment.