BUG/MINOR: http-fetch: Fix calls w/o parentheses of the cookie sample fetches

req.cook, req.cook_val, req.cook_cnt and and their response counterparts may be
called without cookie name. In this case, empty parentheses may be used, or no
parentheses at all. In both, the result must be the same. But only the first one
works. The second one always returns a failure. This patch fixes this bug.

Note that on old versions (< 2.2), both cases fail.

This patch must be backported in all stable versions.

(cherry picked from commit 97fc8da2643531ade4163d6662f13f76fa59d677)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 934630a682fc4b5fb4902c254de17fcbe2ac84ee)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit d6e7b958dfde326932e63a5840e4f2623fb76505)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 8e47c2590f8a72cc31ff5af747fcf3dc000f3397)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
diff --git a/src/http_fetch.c b/src/http_fetch.c
index b2afdbf..7296787 100644
--- a/src/http_fetch.c
+++ b/src/http_fetch.c
@@ -2209,10 +2209,14 @@
 {
 	/* possible keywords: req.cookie / cookie / cook, res.cookie / scook / set-cookie */
 	struct channel *chn = ((kw[0] == 'c' || kw[2] == 'q') ? SMP_REQ_CHN(smp) : SMP_RES_CHN(smp));
+	char *cook = NULL;
+	size_t cook_l = 0;
 	int found = 0;
 
-	if (!args || args->type != ARGT_STR)
-		return 0;
+	if (args && args->type == ARGT_STR) {
+		cook = args->data.str.area;
+		cook_l = args->data.str.data;
+	}
 
 	if (smp->px->options2 & PR_O2_USE_HTX) {
 		/* HTX version */
@@ -2252,7 +2256,7 @@
 				if (!http_find_header(htx, hdr, ctx, 0))
 					goto out;
 
-				if (ctx->value.len < args->data.str.data + 1)
+				if (ctx->value.len < cook_l + 1)
 					continue;
 
 				smp->ctx.a[0] = ctx->value.ptr;
@@ -2262,7 +2266,7 @@
 			smp->data.type = SMP_T_STR;
 			smp->flags |= SMP_F_CONST;
 			smp->ctx.a[0] = http_extract_cookie_value(smp->ctx.a[0], smp->ctx.a[1],
-								  args->data.str.area, args->data.str.data,
+								  cook, cook_l,
 								  (smp->opt & SMP_OPT_DIR) == SMP_OPT_DIR_REQ,
 								  &smp->data.u.str.area,
 								  &smp->data.u.str.data);
@@ -2329,7 +2333,7 @@
 				if (!http_find_header2(hdr_name, hdr_name_len, sol, idx, ctx))
 					goto out;
 
-				if (ctx->vlen < args->data.str.data + 1)
+				if (ctx->vlen < cook_l + 1)
 					continue;
 
 				smp->ctx.a[0] = ctx->line + ctx->val;
@@ -2339,7 +2343,7 @@
 			smp->data.type = SMP_T_STR;
 			smp->flags |= SMP_F_CONST;
 			smp->ctx.a[0] = http_extract_cookie_value(smp->ctx.a[0], smp->ctx.a[1],
-								  args->data.str.area, args->data.str.data,
+								  cook, cook_l,
 								  (smp->opt & SMP_OPT_DIR) == SMP_OPT_DIR_REQ,
 								  &smp->data.u.str.area, &smp->data.u.str.data);
 			if (smp->ctx.a[0]) {
@@ -2385,10 +2389,14 @@
 	/* possible keywords: req.cook_cnt / cook_cnt, res.cook_cnt / scook_cnt */
 	struct channel *chn = ((kw[0] == 'c' || kw[2] == 'q') ? SMP_REQ_CHN(smp) : SMP_RES_CHN(smp));
 	char *val_beg, *val_end;
+	char *cook = NULL;
+	size_t cook_l = 0;
 	int cnt;
 
-	if (!args || args->type != ARGT_STR)
-		return 0;
+	if (args && args->type == ARGT_STR){
+		cook = args->data.str.area;
+		cook_l = args->data.str.data;
+	}
 
 	if (smp->px->options2 & PR_O2_USE_HTX) {
 		/* HTX version */
@@ -2410,7 +2418,7 @@
 				if (!http_find_header(htx, hdr, &ctx, 0))
 					break;
 
-				if (ctx.value.len < args->data.str.data + 1)
+				if (ctx.value.len < cook_l + 1)
 					continue;
 
 				val_beg = ctx.value.ptr;
@@ -2420,7 +2428,7 @@
 			smp->data.type = SMP_T_STR;
 			smp->flags |= SMP_F_CONST;
 			while ((val_beg = http_extract_cookie_value(val_beg, val_end,
-								    args->data.str.area, args->data.str.data,
+								    cook, cook_l,
 								    (smp->opt & SMP_OPT_DIR) == SMP_OPT_DIR_REQ,
 								    &smp->data.u.str.area,
 								    &smp->data.u.str.data))) {
@@ -2458,7 +2466,7 @@
 				if (!http_find_header2(hdr_name, hdr_name_len, sol, idx, &ctx))
 					break;
 
-				if (ctx.vlen < args->data.str.data + 1)
+				if (ctx.vlen < cook_l + 1)
 					continue;
 
 				val_beg = ctx.line + ctx.val;
@@ -2468,7 +2476,7 @@
 			smp->data.type = SMP_T_STR;
 			smp->flags |= SMP_F_CONST;
 			while ((val_beg = http_extract_cookie_value(val_beg, val_end,
-								    args->data.str.area, args->data.str.data,
+								    cook, cook_l,
 								    (smp->opt & SMP_OPT_DIR) == SMP_OPT_DIR_REQ,
 								    &smp->data.u.str.area, &smp->data.u.str.data))) {
 				cnt++;