View Issue Details

IDProjectCategoryView StatusLast Update
0033680FPCFCLpublic2018-05-07 19:51
ReporterengkinAssigned ToMichael Van Canneyt 
PrioritynormalSeverityminorReproducibilityhave not tried
Status closedResolutionfixed 
Product VersionProduct Build 
Target Version3.2.0Fixed in Version3.1.1 
Summary0033680: [Patch] FPHTTPClient.IndexOfHeader may give wrong value
DescriptionIndexOfHeader compares the header in the parameter with a part of similar length of the stored headers which, if the beginning of the stored header happen to equal the parameter, gives wrong result.
Steps To ReproduceAdd the following two headers like Accept and Accept-Language:
AddHeader('Accept','text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8');
AddHeader('Accept-Language','en-US,en;q=0.5');


Now both IndexOfHeader('Accept') and IndexOfHeader('Accept-Language') return the same value pointing at Accept-Language header.
Additional InformationThe included patch is just a simple proposal to fix this bug by adding a colon to the header in the parameter.


It also adds a space for the Cookies header, and replaces the value of an existing header with a new value. These two changes are not related to this bug.
TagsNo tags attached.
Fixed in Revision38910
FPCOldBugId
FPCTarget
Attached Files
  • IndexOfHeader.patch (896 bytes)
    Index: fphttpclient.pp
    ===================================================================
    --- fphttpclient.pp	(revision 38895)
    +++ fphttpclient.pp	(working copy)
    @@ -679,7 +679,7 @@
         end;
       if Assigned(FCookies) then
         begin
    -    L:='Cookie:';
    +    L:='Cookie: ';
         For I:=0 to FCookies.Count-1 do
           begin
           If (I>0) then
    @@ -1303,8 +1303,9 @@
     begin
       j:=IndexOfHeader(HTTPHeaders,Aheader);
       if (J<>-1) then
    -    HTTPHeaders.Delete(j);
    -  HTTPHeaders.Add(AHeader+': '+Avalue);
    +    HTTPHeaders[j] := AHeader+': '+Avalue
    +  else
    +    HTTPHeaders.Add(AHeader+': '+Avalue);
     end;
     
     
    @@ -1315,8 +1316,8 @@
       L : Integer;
       H : String;
     begin
    -  H:=LowerCase(Aheader);
    -  l:=Length(AHeader);
    +  H:=LowerCase(AHeader)+':';
    +  l:=Length(H);
       Result:=HTTPHeaders.Count-1;
       While (Result>=0) and ((LowerCase(Copy(HTTPHeaders[Result],1,l)))<>h) do
         Dec(Result);
    
    IndexOfHeader.patch (896 bytes)
  • project1.lpr (503 bytes)

Activities

engkin

2018-05-03 06:50

reporter  

IndexOfHeader.patch (896 bytes)
Index: fphttpclient.pp
===================================================================
--- fphttpclient.pp	(revision 38895)
+++ fphttpclient.pp	(working copy)
@@ -679,7 +679,7 @@
     end;
   if Assigned(FCookies) then
     begin
-    L:='Cookie:';
+    L:='Cookie: ';
     For I:=0 to FCookies.Count-1 do
       begin
       If (I>0) then
@@ -1303,8 +1303,9 @@
 begin
   j:=IndexOfHeader(HTTPHeaders,Aheader);
   if (J<>-1) then
-    HTTPHeaders.Delete(j);
-  HTTPHeaders.Add(AHeader+': '+Avalue);
+    HTTPHeaders[j] := AHeader+': '+Avalue
+  else
+    HTTPHeaders.Add(AHeader+': '+Avalue);
 end;
 
 
@@ -1315,8 +1316,8 @@
   L : Integer;
   H : String;
 begin
-  H:=LowerCase(Aheader);
-  l:=Length(AHeader);
+  H:=LowerCase(AHeader)+':';
+  l:=Length(H);
   Result:=HTTPHeaders.Count-1;
   While (Result>=0) and ((LowerCase(Copy(HTTPHeaders[Result],1,l)))<>h) do
     Dec(Result);
IndexOfHeader.patch (896 bytes)

engkin

2018-05-03 17:42

reporter  

project1.lpr (503 bytes)

engkin

2018-05-03 17:43

reporter   ~0108131

Just attached a sample project that shows the problem.

Michael Van Canneyt

2018-05-05 17:10

administrator   ~0108158

Fixed, thank you very much for the patch!

engkin

2018-05-07 19:51

reporter   ~0108178

You are welcome!

Issue History

Date Modified Username Field Change
2018-05-03 06:50 engkin New Issue
2018-05-03 06:50 engkin File Added: IndexOfHeader.patch
2018-05-03 09:09 Michael Van Canneyt Assigned To => Michael Van Canneyt
2018-05-03 09:09 Michael Van Canneyt Status new => assigned
2018-05-03 17:42 engkin File Added: project1.lpr
2018-05-03 17:43 engkin Note Added: 0108131
2018-05-05 17:10 Michael Van Canneyt Fixed in Revision => 38910
2018-05-05 17:10 Michael Van Canneyt Note Added: 0108158
2018-05-05 17:10 Michael Van Canneyt Status assigned => resolved
2018-05-05 17:10 Michael Van Canneyt Fixed in Version => 3.1.1
2018-05-05 17:10 Michael Van Canneyt Resolution open => fixed
2018-05-05 17:10 Michael Van Canneyt Target Version => 3.2.0
2018-05-07 19:51 engkin Note Added: 0108178
2018-05-07 19:51 engkin Status resolved => closed