Fossil SCM

Refuse an SCGI request whose header length has more digits than any real header needs, before the length overflows an int.

dmestas 2026-11-17 13:28 UTC small-fixes-2
Commit 7473314f34cc95e73baa7ae66fd6d868ca5bacbac70fc8f54ea4b8676cfc71a3
1 file changed +1
+1
--- src/cgi.c
+++ src/cgi.c
@@ -2540,10 +2540,11 @@
25402540
int nRead;
25412541
int c, n, m;
25422542
25432543
assert( !g.httpUseSSL );
25442544
while( (c = fgetc(g.httpIn))!=EOF && fossil_isdigit((char)c) ){
2545
+ if( nHdr>=100000000 ) malformed_request("SCGI header too long");
25452546
nHdr = nHdr*10 + (char)c - '0';
25462547
}
25472548
if( nHdr<16 ) malformed_request("SCGI header too short");
25482549
zToFree = zHdr = fossil_malloc(nHdr);
25492550
nRead = (int)fread(zHdr, 1, nHdr, g.httpIn);
25502551
--- src/cgi.c
+++ src/cgi.c
@@ -2540,10 +2540,11 @@
2540 int nRead;
2541 int c, n, m;
2542
2543 assert( !g.httpUseSSL );
2544 while( (c = fgetc(g.httpIn))!=EOF && fossil_isdigit((char)c) ){
 
2545 nHdr = nHdr*10 + (char)c - '0';
2546 }
2547 if( nHdr<16 ) malformed_request("SCGI header too short");
2548 zToFree = zHdr = fossil_malloc(nHdr);
2549 nRead = (int)fread(zHdr, 1, nHdr, g.httpIn);
2550
--- src/cgi.c
+++ src/cgi.c
@@ -2540,10 +2540,11 @@
2540 int nRead;
2541 int c, n, m;
2542
2543 assert( !g.httpUseSSL );
2544 while( (c = fgetc(g.httpIn))!=EOF && fossil_isdigit((char)c) ){
2545 if( nHdr>=100000000 ) malformed_request("SCGI header too long");
2546 nHdr = nHdr*10 + (char)c - '0';
2547 }
2548 if( nHdr<16 ) malformed_request("SCGI header too short");
2549 zToFree = zHdr = fossil_malloc(nHdr);
2550 nRead = (int)fread(zHdr, 1, nHdr, g.httpIn);
2551

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button