]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MINOR: map: split "add map/acl" payload keys on line breaks
authorOlivier Houchard <ohouchard@haproxy.com>
Wed, 18 Nov 2026 14:23:21 +0000 (15:23 +0100)
committerOlivier Houchard <cognet@ci0.org>
Wed, 18 Nov 2026 14:22:21 +0000 (15:22 +0100)
The payload of "add map" and "add acl" contains one entry per line, but
the key was only split on spaces and tabs. A map line without a value
was thus merged with the next line into a single bogus entry instead of
being reported as an error, as is done for the last line. For "add acl",
whose patterns contain no space, all the lines were merged into a single
pattern, and the parser then stepped past the end of the payload, where
it only reads the payload terminator line.

Let's also stop the key on line breaks, and consider that a line without
a space or tab after the key has no value.

This was introduced in 1.9 by commit 25650ce51 ("MINOR: map: Add payload
support to "add map"") and may be backported to all stable branches.

src/map.c

index 4a93797413cd5f1df9df428ecfc2fdc86a13fca8..981d8f6eead60cb62b977a34b9e8e68c00a60260 100644 (file)
--- a/src/map.c
+++ b/src/map.c
@@ -926,6 +926,7 @@ static int cli_parse_add_map(char **args, char *payload, struct appctx *appctx,
                        char *key   = args[3];
                        char *value = args[4];
                        size_t l;
+                       char delim;
 
                        if (payload) {
                                /* key and value passed as payload, one pair per line */
@@ -933,23 +934,30 @@ static int cli_parse_add_map(char **args, char *payload, struct appctx *appctx,
                                        break;
 
                                key = payload;
-                               l = strcspn(key, " \t");
+                               l = strcspn(key, " \t\n");
                                payload += l;
-
-                               if (!*payload && ctx->display_flags == PAT_REF_MAP)
-                                       return cli_dynerr(appctx, memprintf(&err, "Missing value for key '%s'.\n", key));
-
+                               delim = *payload;
                                key[l] = 0;
-                               payload++;
 
-                               /* value */
-                               payload += strspn(payload, " \t");
-                               value = payload;
-                               l = strcspn(value, "\n");
-                               payload += l;
-                               if (*payload)
+                               if (delim != ' ' && delim != '\t') {
+                                       /* no value on this line */
+                                       if (ctx->display_flags == PAT_REF_MAP)
+                                               return cli_dynerr(appctx, memprintf(&err, "Missing value for key '%s'.\n", key));
+                                       if (delim)
+                                               payload++;
+                               }
+                               else {
                                        payload++;
-                               value[l] = 0;
+
+                                       /* value */
+                                       payload += strspn(payload, " \t");
+                                       value = payload;
+                                       l = strcspn(value, "\n");
+                                       payload += l;
+                                       if (*payload)
+                                               payload++;
+                                       value[l] = 0;
+                               }
                        }
 
                        if (ctx->display_flags != PAT_REF_MAP)