]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MINOR: mux-h1: convert the <from> argument of h1-case-adjust to lower case
authorChristopher Faulet <cfaulet@haproxy.com>
Wed, 7 Oct 2026 14:05:00 +0000 (16:05 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 16 Oct 2026 17:10:27 +0000 (19:10 +0200)
The "h1-case-adjust" global directive (and the file loaded with
"h1-case-adjust-file") takes the header name to match in lower case, as
specified in the documentation, but it was not checked. So with:

    h1-case-adjust X-Up X-Up

the rule was accepted without any warning but never matched since header
names are looked up in lower case, and "x-up" was still emitted. Let's
convert <from> to lower case before inserting it in the map, which also
makes duplicate detection work regardless of the case.

It could be backported to all supported versions.

src/mux_h1.c

index 0a6d29e801cc4bb46b41f4c6f072993f641ef43b..093a749f9b2499f601199d5ceb36ab6a7805a9ee 100644 (file)
@@ -5847,6 +5847,7 @@ static int h1_show_sd(struct buffer *msg, struct sedesc *sd, const char *pfx)
 static int add_hdr_case_adjust(const char *from, const char *to, char **err)
 {
        struct h1_hdr_entry *entry;
+       char *key, *p;
 
        /* Be sure there is a non-empty <to> */
        if (!strlen(to)) {
@@ -5860,24 +5861,36 @@ static int add_hdr_case_adjust(const char *from, const char *to, char **err)
                return -1;
        }
 
+       /* <from> is looked up using lower case header names, so it is
+        * converted to lower case.
+        */
+       key = strdup(from);
+       if (!key) {
+               memprintf(err, "out of memory");
+               return -1;
+       }
+       for (p = key; *p; p++)
+               *p = tolower((unsigned char)*p);
+
        /* Be sure <from> does not already existsin the tree */
-       if (ebis_lookup(&hdrs_map.map, from)) {
+       if (ebis_lookup(&hdrs_map.map, key)) {
                memprintf(err, "duplicate entry '%s'", from);
+               free(key);
                return -1;
        }
 
        /* Create the entry and insert it in the tree */
        entry = malloc(sizeof(*entry));
        if (!entry) {
+               free(key);
                memprintf(err, "out of memory");
                return -1;
        }
 
-       entry->node.key = strdup(from);
+       entry->node.key = key;
        entry->name = ist(strdup(to));
-       if (!entry->node.key || !isttest(entry->name)) {
+       if (!isttest(entry->name)) {
                free(entry->node.key);
-               istfree(&entry->name);
                free(entry);
                memprintf(err, "out of memory");
                return -1;