diff --git a/CVE-2025-23016.patch b/CVE-2025-23016.patch index c4feadc87c5a8017a3fa63eed4da614bbd170330..4a4e091d945f8d7f13e87f206873e469f88285e6 100644 --- a/CVE-2025-23016.patch +++ b/CVE-2025-23016.patch @@ -36,3 +36,82 @@ index 4ffe318..99c3630 100644 } /* * nameLen and valueLen are now valid; read the name and value +From 7c476394e799f39f749d7a7a50f62e5d3ec8db61 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= +Date: Mon, 19 May 2025 13:49:32 +0200 +Subject: [PATCH] Fix size_t overflow in Malloc() argument in ReadParams() +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +There were still two issues after commit +b0eabcaf4d4f371514891a52115c746815c2ff15 (Update fcgiapp.c, Fixing an +integer overflow (CVE-2025-23016)): + +* Signed int overflow in "nameLen + valueLen + 2" expression. + +* Sizes of size_t and int types are in general unrelated. + +This fix resolves both of the issues. + +Related to CVE-2025-23016. +Resolve #67. + +Signed-off-by: Petr Písař +--- + libfcgi/fcgiapp.c | 13 ++++++++++--- + 1 file changed, 10 insertions(+), 3 deletions(-) + +diff --git a/libfcgi/fcgiapp.c b/libfcgi/fcgiapp.c +index 99c3630..0cd3dd1 100644 +--- a/libfcgi/fcgiapp.c ++++ b/libfcgi/fcgiapp.c +@@ -18,6 +18,7 @@ + #include /* for memchr() */ + #include + #include ++#include + #include + #include + #include +@@ -1160,6 +1161,7 @@ char *FCGX_GetParam(const char *name, FCGX_ParamArray envp) + static int ReadParams(Params *paramsPtr, FCGX_Stream *stream) + { + int nameLen, valueLen; ++ size_t totalLen; + unsigned char lenBuff[3]; + char *nameValue; + +@@ -1175,7 +1177,7 @@ static int ReadParams(Params *paramsPtr, FCGX_Stream *stream) + } + nameLen = ((nameLen & 0x7f) << 24) + (lenBuff[0] << 16) + + (lenBuff[1] << 8) + lenBuff[2]; +- if (nameLen >= INT_MAX) { ++ if (nameLen >= INT_MAX || nameLen >= SIZE_MAX) { + SetError(stream, FCGX_PARAMS_ERROR); + return -1; + } +@@ -1191,16 +1193,21 @@ static int ReadParams(Params *paramsPtr, FCGX_Stream *stream) + } + valueLen = ((valueLen & 0x7f) << 24) + (lenBuff[0] << 16) + + (lenBuff[1] << 8) + lenBuff[2]; +- if (valueLen >= INT_MAX) { ++ if (valueLen >= INT_MAX || valueLen >= SIZE_MAX) { + SetError(stream, FCGX_PARAMS_ERROR); + return -1; + } + } ++ totalLen = (size_t)nameLen + (size_t)valueLen + 2u; ++ if (totalLen < (size_t)nameLen || totalLen < (size_t)valueLen) { ++ SetError(stream, FCGX_PARAMS_ERROR); ++ return -1; ++ } + /* + * nameLen and valueLen are now valid; read the name and value + * from stream and construct a standard environment entry. + */ +- nameValue = (char *)Malloc(nameLen + valueLen + 2); ++ nameValue = (char *)Malloc(totalLen); + if(FCGX_GetStr(nameValue, nameLen, stream) != nameLen) { + SetError(stream, FCGX_PARAMS_ERROR); + free(nameValue); diff --git a/fcgi.spec b/fcgi.spec index d0403c107445085ff512be1c7076aa9fe2723e6f..29095fed84c9da822ad180f6b67ffa40da7a5050 100644 --- a/fcgi.spec +++ b/fcgi.spec @@ -1,6 +1,6 @@ Name: fcgi Version: 2.4.2 -Release: 2 +Release: 3 Summary: FastCGI development kit License: OML URL: https://github.com/FastCGI-Archives/fcgi2 @@ -58,6 +58,9 @@ rm -rf %{buildroot}%{_libdir}/pkgconfig/fcgi.pc %doc doc/ %changelog +* Sat Nov 29 2025 Funda Wang - 2.4.2-3 +- more patches related to CVE-2025-23016 + * Sun Apr 27 2025 wangkai <13474090681@163.com> - 2.4.2-2 - Fix CVE-2025-23016