]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Fix header name mismatching after rev.14870
authorAmos Jeffries <squid3@treenet.co.nz>
Thu, 6 Oct 2016 21:02:32 +0000 (10:02 +1300)
committerAmos Jeffries <squid3@treenet.co.nz>
Thu, 6 Oct 2016 21:02:32 +0000 (10:02 +1300)
When a mime header set contains two custom headers and one
name is the prefix for the other the name lookup using a
fixed length for String comparison can wrongly match the
longer header as being equal to the shorter one, since only
the identical prefix portion is compared.

To avoid this we must check that the lengths are also matching.

This also improves performance very slightly as the common
case for custom headers is to have an "X-" prefix which is
slower to compare than total length. Headers having same
length and same prefix is quite rare.

src/HttpHeader.cc

index e1ebf4bb08ded650fd81915bb6bfbcc2687ec3d4..2191f91474df0b12df17ec7b0fb4bd0e64d4ee0c 100644 (file)
@@ -882,7 +882,7 @@ HttpHeader::getByNameIfPresent(const char *name, int namelen, String &result) co
     /* Sorry, an unknown header name. Do linear search */
     bool found = false;
     while ((e = getEntry(&pos))) {
-        if (e->id == Http::HdrType::OTHER && e->name.caseCmp(name, namelen) == 0) {
+        if (e->id == Http::HdrType::OTHER && e->name.size() == static_cast<String::size_type>(namelen) && e->name.caseCmp(name, namelen) == 0) {
             found = true;
             strListAdd(&result, e->value.termedBuf(), ',');
         }