Fossil SCM

Additional cleanup of the CGI handling when using SSH. Specifically the use of cgi_init() introduced some side-effects that caused Fossil to return errors when using ForceCommand to require "fossil http" interface.

andybradford 2025-10-16 06:07 trunk
Commit 088be210db8abad5cf9aec8b68c1d8113e14b707fbf9e6fc3ab08a013a68f91d
1 file changed +9 -15
+9 -15
--- src/cgi.c
+++ src/cgi.c
@@ -2290,12 +2290,11 @@
22902290
*/
22912291
void cgi_handle_ssh_http_request(const char *zIpAddr){
22922292
static int nCycles = 0;
22932293
static char *zCmd = 0;
22942294
char *z, *zToken;
2295
- const char *zType = 0;
2296
- int i, content_length = 0;
2295
+ int i;
22972296
char zLine[2000]; /* A single line of input. */
22982297
22992298
assert( !g.httpUseSSL );
23002299
#ifdef FOSSIL_ENABLE_JSON
23012300
if( nCycles==0 ){ json_bootstrap_early(); }
@@ -2386,13 +2385,19 @@
23862385
zVal[i] = 0;
23872386
for(i=0; zFieldName[i]; i++){
23882387
zFieldName[i] = fossil_tolower(zFieldName[i]);
23892388
}
23902389
if( fossil_strcmp(zFieldName,"content-length:")==0 ){
2391
- content_length = atoi(zVal);
2390
+ if( nCycles==0 ){
2391
+ cgi_setenv("CONTENT_LENGTH", zVal);
2392
+ }else{
2393
+ cgi_replace_parameter("CONTENT_LENGTH", zVal);
2394
+ }
23922395
}else if( fossil_strcmp(zFieldName,"content-type:")==0 ){
2393
- g.zContentType = zType = fossil_strdup(zVal);
2396
+ if( nCycles==0 ){
2397
+ cgi_setenv("CONTENT_TYPE", zVal);
2398
+ }
23942399
}else if( fossil_strcmp(zFieldName,"host:")==0 ){
23952400
if( nCycles==0 ){
23962401
cgi_setenv("HTTP_HOST", zVal);
23972402
}
23982403
}else if( fossil_strcmp(zFieldName,"user-agent:")==0 ){
@@ -2419,21 +2424,10 @@
24192424
}
24202425
24212426
cgi_reset_content();
24222427
cgi_destination(CGI_BODY);
24232428
2424
- if( content_length>0 && zType ){
2425
- blob_zero(&g.cgiIn);
2426
- if( fossil_strcmp(zType, "application/x-fossil")==0 ){
2427
- blob_read_from_channel(&g.cgiIn, g.httpIn, content_length);
2428
- blob_uncompress(&g.cgiIn, &g.cgiIn);
2429
- }else if( fossil_strcmp(zType, "application/x-fossil-debug")==0 ){
2430
- blob_read_from_channel(&g.cgiIn, g.httpIn, content_length);
2431
- }else if( fossil_strcmp(zType, "application/x-fossil-uncompressed")==0 ){
2432
- blob_read_from_channel(&g.cgiIn, g.httpIn, content_length);
2433
- }
2434
- }
24352429
cgi_init();
24362430
cgi_trace(0);
24372431
nCycles++;
24382432
}
24392433
24402434
--- src/cgi.c
+++ src/cgi.c
@@ -2290,12 +2290,11 @@
2290 */
2291 void cgi_handle_ssh_http_request(const char *zIpAddr){
2292 static int nCycles = 0;
2293 static char *zCmd = 0;
2294 char *z, *zToken;
2295 const char *zType = 0;
2296 int i, content_length = 0;
2297 char zLine[2000]; /* A single line of input. */
2298
2299 assert( !g.httpUseSSL );
2300 #ifdef FOSSIL_ENABLE_JSON
2301 if( nCycles==0 ){ json_bootstrap_early(); }
@@ -2386,13 +2385,19 @@
2386 zVal[i] = 0;
2387 for(i=0; zFieldName[i]; i++){
2388 zFieldName[i] = fossil_tolower(zFieldName[i]);
2389 }
2390 if( fossil_strcmp(zFieldName,"content-length:")==0 ){
2391 content_length = atoi(zVal);
 
 
 
 
2392 }else if( fossil_strcmp(zFieldName,"content-type:")==0 ){
2393 g.zContentType = zType = fossil_strdup(zVal);
 
 
2394 }else if( fossil_strcmp(zFieldName,"host:")==0 ){
2395 if( nCycles==0 ){
2396 cgi_setenv("HTTP_HOST", zVal);
2397 }
2398 }else if( fossil_strcmp(zFieldName,"user-agent:")==0 ){
@@ -2419,21 +2424,10 @@
2419 }
2420
2421 cgi_reset_content();
2422 cgi_destination(CGI_BODY);
2423
2424 if( content_length>0 && zType ){
2425 blob_zero(&g.cgiIn);
2426 if( fossil_strcmp(zType, "application/x-fossil")==0 ){
2427 blob_read_from_channel(&g.cgiIn, g.httpIn, content_length);
2428 blob_uncompress(&g.cgiIn, &g.cgiIn);
2429 }else if( fossil_strcmp(zType, "application/x-fossil-debug")==0 ){
2430 blob_read_from_channel(&g.cgiIn, g.httpIn, content_length);
2431 }else if( fossil_strcmp(zType, "application/x-fossil-uncompressed")==0 ){
2432 blob_read_from_channel(&g.cgiIn, g.httpIn, content_length);
2433 }
2434 }
2435 cgi_init();
2436 cgi_trace(0);
2437 nCycles++;
2438 }
2439
2440
--- src/cgi.c
+++ src/cgi.c
@@ -2290,12 +2290,11 @@
2290 */
2291 void cgi_handle_ssh_http_request(const char *zIpAddr){
2292 static int nCycles = 0;
2293 static char *zCmd = 0;
2294 char *z, *zToken;
2295 int i;
 
2296 char zLine[2000]; /* A single line of input. */
2297
2298 assert( !g.httpUseSSL );
2299 #ifdef FOSSIL_ENABLE_JSON
2300 if( nCycles==0 ){ json_bootstrap_early(); }
@@ -2386,13 +2385,19 @@
2385 zVal[i] = 0;
2386 for(i=0; zFieldName[i]; i++){
2387 zFieldName[i] = fossil_tolower(zFieldName[i]);
2388 }
2389 if( fossil_strcmp(zFieldName,"content-length:")==0 ){
2390 if( nCycles==0 ){
2391 cgi_setenv("CONTENT_LENGTH", zVal);
2392 }else{
2393 cgi_replace_parameter("CONTENT_LENGTH", zVal);
2394 }
2395 }else if( fossil_strcmp(zFieldName,"content-type:")==0 ){
2396 if( nCycles==0 ){
2397 cgi_setenv("CONTENT_TYPE", zVal);
2398 }
2399 }else if( fossil_strcmp(zFieldName,"host:")==0 ){
2400 if( nCycles==0 ){
2401 cgi_setenv("HTTP_HOST", zVal);
2402 }
2403 }else if( fossil_strcmp(zFieldName,"user-agent:")==0 ){
@@ -2419,21 +2424,10 @@
2424 }
2425
2426 cgi_reset_content();
2427 cgi_destination(CGI_BODY);
2428
 
 
 
 
 
 
 
 
 
 
 
2429 cgi_init();
2430 cgi_trace(0);
2431 nCycles++;
2432 }
2433
2434

Keyboard Shortcuts

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