From 1997a487f7092b0fbbded4acffb07d2b8f6c9e3d Mon Sep 17 00:00:00 2001 From: Amos Jeffries Date: Fri, 7 Oct 2016 10:02:32 +1300 Subject: [PATCH] Fix header name mismatching after rev.14870 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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/HttpHeader.cc b/src/HttpHeader.cc index e1ebf4bb08..2191f91474 100644 --- a/src/HttpHeader.cc +++ b/src/HttpHeader.cc @@ -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(namelen) && e->name.caseCmp(name, namelen) == 0) { found = true; strListAdd(&result, e->value.termedBuf(), ','); } -- 2.47.2