Skip to content

Commit

Permalink
Limit Server::inBuf growth (#1898)
Browse files Browse the repository at this point in the history
After a ReadNow() call, the buffer length must not exceed accumulation
limits (e.g., client_request_buffer_max_size). SBuf::reserve() alone
cannot reliably enforce those limits because it does not decrease SBuf
space; various SBuf manipulations may lead to excessive SBuf space. When
filled by ReadNow(), that space exceeds the limit.

This change uses documented CommIoCbParams::size trick to limit how much
Comm::ReadNow() may read, obeying SQUID_TCP_SO_RCVBUF (server-to-Squid)
and client_request_buffer_max_size (client-to-Squid) accumulation limit.
  • Loading branch information
eduard-bagdasaryan authored and squid-anubis committed Sep 9, 2024
1 parent 5370d36 commit 5f31e83
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/adaptation/icap/Xaction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ void Adaptation::Icap::Xaction::noteCommRead(const CommIoCbParams &io)

CommIoCbParams rd(this); // will be expanded with ReadNow results
rd.conn = io.conn;
rd.size = SQUID_TCP_SO_RCVBUF - readBuf.length();

switch (Comm::ReadNow(rd, readBuf)) {
case Comm::INPROGRESS:
Expand Down
3 changes: 3 additions & 0 deletions src/servers/Server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ Server::doClientRead(const CommIoCbParams &io)

CommIoCbParams rd(this); // will be expanded with ReadNow results
rd.conn = io.conn;
Assure(Config.maxRequestBufferSize > inBuf.length());
rd.size = Config.maxRequestBufferSize - inBuf.length();

switch (Comm::ReadNow(rd, inBuf)) {
case Comm::INPROGRESS:

Expand Down

0 comments on commit 5f31e83

Please sign in to comment.