Fossil SCM

Fix parsing of "Connection:" HTTP headers with multiple values.

florian 2024-04-20 14:41 trunk
Commit 7ac3db68d5a8204edf98b842fdb1339b07edd4d317a7f53dd27786075b1954f7
1 file changed +13 -8
+13 -8
--- src/http.c
+++ src/http.c
@@ -569,18 +569,23 @@
569569
closeConnection = 0;
570570
}else if( fossil_strnicmp(zLine, "content-length:", 15)==0 ){
571571
for(i=15; fossil_isspace(zLine[i]); i++){}
572572
iLength = atoi(&zLine[i]);
573573
}else if( fossil_strnicmp(zLine, "connection:", 11)==0 ){
574
- char c;
575
- for(i=11; fossil_isspace(zLine[i]); i++){}
576
- c = zLine[i];
577
- if( c=='c' || c=='C' ){
578
- closeConnection = 1;
579
- }else if( c=='k' || c=='K' ){
580
- closeConnection = 0;
581
- }
574
+ int j; /* Points to end of value (space, semicolon or zero terminator). */
575
+ i = 11;
576
+ do{
577
+ while( fossil_isspace(zLine[i]) || zLine[i]==',' ) i++;
578
+ j = i;
579
+ while( !fossil_isspace(zLine[j]) && zLine[j]!=',' && zLine[j] ) j++;
580
+ if( j-i==5 && fossil_strnicmp(&zLine[i], "close", 5)==0 ){
581
+ closeConnection = 1;
582
+ }else if( j-i==10 && fossil_strnicmp(&zLine[i], "keep-alive", 10)==0 ){
583
+ closeConnection = 0;
584
+ }
585
+ i = j;
586
+ }while( zLine[i] );
582587
}else if( ( rc==301 || rc==302 || rc==307 || rc==308 ) &&
583588
fossil_strnicmp(zLine, "location:", 9)==0 ){
584589
int i, j;
585590
int wasHttps;
586591
587592
--- src/http.c
+++ src/http.c
@@ -569,18 +569,23 @@
569 closeConnection = 0;
570 }else if( fossil_strnicmp(zLine, "content-length:", 15)==0 ){
571 for(i=15; fossil_isspace(zLine[i]); i++){}
572 iLength = atoi(&zLine[i]);
573 }else if( fossil_strnicmp(zLine, "connection:", 11)==0 ){
574 char c;
575 for(i=11; fossil_isspace(zLine[i]); i++){}
576 c = zLine[i];
577 if( c=='c' || c=='C' ){
578 closeConnection = 1;
579 }else if( c=='k' || c=='K' ){
580 closeConnection = 0;
581 }
 
 
 
 
 
582 }else if( ( rc==301 || rc==302 || rc==307 || rc==308 ) &&
583 fossil_strnicmp(zLine, "location:", 9)==0 ){
584 int i, j;
585 int wasHttps;
586
587
--- src/http.c
+++ src/http.c
@@ -569,18 +569,23 @@
569 closeConnection = 0;
570 }else if( fossil_strnicmp(zLine, "content-length:", 15)==0 ){
571 for(i=15; fossil_isspace(zLine[i]); i++){}
572 iLength = atoi(&zLine[i]);
573 }else if( fossil_strnicmp(zLine, "connection:", 11)==0 ){
574 int j; /* Points to end of value (space, semicolon or zero terminator). */
575 i = 11;
576 do{
577 while( fossil_isspace(zLine[i]) || zLine[i]==',' ) i++;
578 j = i;
579 while( !fossil_isspace(zLine[j]) && zLine[j]!=',' && zLine[j] ) j++;
580 if( j-i==5 && fossil_strnicmp(&zLine[i], "close", 5)==0 ){
581 closeConnection = 1;
582 }else if( j-i==10 && fossil_strnicmp(&zLine[i], "keep-alive", 10)==0 ){
583 closeConnection = 0;
584 }
585 i = j;
586 }while( zLine[i] );
587 }else if( ( rc==301 || rc==302 || rc==307 || rc==308 ) &&
588 fossil_strnicmp(zLine, "location:", 9)==0 ){
589 int i, j;
590 int wasHttps;
591
592

Keyboard Shortcuts

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