From: Alex Bason Date: Sun, 15 Oct 2023 13:04:47 +0000 (+0000) Subject: Fix stack buffer overflow when parsing Digest Authorization (#1517) X-Git-Tag: SQUID_7_0_1~328 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=538ad49f1534abcfca1b305faf1b0e2663b6c8da;p=thirdparty%2Fsquid.git Fix stack buffer overflow when parsing Digest Authorization (#1517) The bug was discovered and detailed by Joshua Rogers at https://megamansec.github.io/Squid-Security-Audit/digest-overflow.html where it was filed as "Stack Buffer Overflow in Digest Authentication". --- diff --git a/src/auth/digest/Config.cc b/src/auth/digest/Config.cc index 4fc3666b83..a3c9e93882 100644 --- a/src/auth/digest/Config.cc +++ b/src/auth/digest/Config.cc @@ -826,11 +826,15 @@ Auth::Digest::Config::decode(char const *proxy_auth, const HttpRequest *request, break; case DIGEST_NC: - if (value.size() != 8) { + if (value.size() == 8) { + // for historical reasons, the nc value MUST be exactly 8 bytes + static_assert(sizeof(digest_request->nc) == 8 + 1); + xstrncpy(digest_request->nc, value.rawBuf(), value.size() + 1); + debugs(29, 9, "Found noncecount '" << digest_request->nc << "'"); + } else { debugs(29, 9, "Invalid nc '" << value << "' in '" << temp << "'"); + digest_request->nc[0] = 0; } - xstrncpy(digest_request->nc, value.rawBuf(), value.size() + 1); - debugs(29, 9, "Found noncecount '" << digest_request->nc << "'"); break; case DIGEST_CNONCE: