From 267f4753f16869cd60e809f04b92f552a1d2cc60 Mon Sep 17 00:00:00 2001
From: Maciej Zdeb <maciej@zdeb.pl>
Date: Fri, 20 Nov 2020 12:12:24 +0000
Subject: [PATCH 1/2] BUG/MINOR: http_htx: Fix searching headers by substring

Function __http_find_header is used to search headers by name using specified
matching method. Matching by substring returned unexpected results due to wrong
length of substring supplied to strnistr function.

Fixed also the boolean condition by inverting it, as we're interested in
headers that contains the substring.

This patch should be backported as far as 2.2
---
 src/http_htx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/http_htx.c b/src/http_htx.c
index b27b0836c..9570b1ea7 100644
--- a/src/http_htx.c
+++ b/src/http_htx.c
@@ -201,7 +201,7 @@ static int __http_find_header(const struct htx *htx, const void *pattern, struct
 					goto next_blk;
 				break;
 			case HTTP_FIND_FL_MATCH_SUB:
-				if (strnistr(n.ptr, n.len, name.ptr, n.len) != NULL)
+				if (!strnistr(n.ptr, n.len, name.ptr, name.len))
 					goto next_blk;
 				break;
 			default:
-- 
2.17.1

