]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: http: hdr_cnt would not count any header when called without name
authorWilly Tarreau <w@1wt.eu>
Wed, 1 Apr 2015 17:16:09 +0000 (19:16 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 1 Apr 2015 17:16:09 +0000 (19:16 +0200)
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.

src/proto_http.c

index 24de4abf32d9009e46ab998c9b0ff2c9ffaadf07..d1cd042a15134949eb8a88b9025eb47eb2c8e1cd 100644 (file)
@@ -10239,15 +10239,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;
@@ -10359,15 +10363,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;