From: Olivier Houchard Date: Wed, 18 Nov 2026 14:23:21 +0000 (+0100) Subject: BUG/MINOR: map: split "add map/acl" payload keys on line breaks X-Git-Tag: v3.5-dev13~10 X-Git-Url: https://git.kaiwu.me/web/%22data:,/doc/static/%7B@url%7D?a=commitdiff_plain;h=bd685d941d2531e2e635ea1ce602273b63f50e3c;p=haproxy.git BUG/MINOR: map: split "add map/acl" payload keys on line breaks 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. --- diff --git a/src/map.c b/src/map.c index 4a9379741..981d8f6ee 100644 --- 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)