SHA256
1
0
forked from pool/haproxy
haproxy/0009-BUG-MEDIUM-http-hdr_cnt-would-not-count-any-header-w.patch

71 lines
2.2 KiB
Diff

From 2943734024525d4b9aeec13cca2c1d230c358ee5 Mon Sep 17 00:00:00 2001
From: Willy Tarreau <w@1wt.eu>
Date: Wed, 1 Apr 2015 19:16:09 +0200
Subject: [PATCH 9/9] BUG/MEDIUM: http: hdr_cnt would not count any header when
called without name
It's documented that these sample fetch functions should count all headers
and/or all values when called with no name but in practice it's not what is
being done as a missing name causes an immediate return and an absence of
result.
This bug is present in 1.5 as well and must be backported.
(cherry picked from commit 601a4d1741100d7a861b6d9b66561335c9911277)
---
src/proto_http.c | 20 ++++++++++++++------
1 file changed, 14 insertions(+), 6 deletions(-)
diff --git a/src/proto_http.c b/src/proto_http.c
index c49c4f4..ccd52ad 100644
--- a/src/proto_http.c
+++ b/src/proto_http.c
@@ -10014,15 +10014,19 @@ smp_fetch_fhdr_cnt(struct proxy *px, struct session *l4, void *l7, unsigned int
struct hdr_ctx ctx;
const struct http_msg *msg = ((opt & SMP_OPT_DIR) == SMP_OPT_DIR_REQ) ? &txn->req : &txn->rsp;
int cnt;
+ const char *name = NULL;
+ int len = 0;
- if (!args || args->type != ARGT_STR)
- return 0;
+ if (args && args->type == ARGT_STR) {
+ name = args->data.str.str;
+ len = args->data.str.len;
+ }
CHECK_HTTP_MESSAGE_FIRST();
ctx.idx = 0;
cnt = 0;
- while (http_find_full_header2(args->data.str.str, args->data.str.len, msg->chn->buf->p, idx, &ctx))
+ while (http_find_full_header2(name, len, msg->chn->buf->p, idx, &ctx))
cnt++;
smp->type = SMP_T_UINT;
@@ -10101,15 +10105,19 @@ smp_fetch_hdr_cnt(struct proxy *px, struct session *l4, void *l7, unsigned int o
struct hdr_ctx ctx;
const struct http_msg *msg = ((opt & SMP_OPT_DIR) == SMP_OPT_DIR_REQ) ? &txn->req : &txn->rsp;
int cnt;
+ const char *name = NULL;
+ int len = 0;
- if (!args || args->type != ARGT_STR)
- return 0;
+ if (args && args->type == ARGT_STR) {
+ name = args->data.str.str;
+ len = args->data.str.len;
+ }
CHECK_HTTP_MESSAGE_FIRST();
ctx.idx = 0;
cnt = 0;
- while (http_find_header2(args->data.str.str, args->data.str.len, msg->chn->buf->p, idx, &ctx))
+ while (http_find_header2(name, len, msg->chn->buf->p, idx, &ctx))
cnt++;
smp->type = SMP_T_UINT;
--
2.1.4