]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-var-expand: Fix list manipulation in make_new_program()
authorAki Tuomi <aki.tuomi@open-xchange.com>
Mon, 10 Nov 2025 07:39:04 +0000 (09:39 +0200)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Tue, 11 Nov 2025 10:17:51 +0000 (10:17 +0000)
Fixes signal 11 crash when handling multiple chained programs like
hello%{}world.

src/lib-var-expand/test-var-expand.c
src/lib-var-expand/var-expand-parser.y

index 2e7ba232a7bbc82ee5ddfb7c37df594e84556d5e..750ed65c49fdbe9d019ff740b8e316789ac193d0 100644 (file)
@@ -95,6 +95,15 @@ static void test_var_expand_builtin_filters(void) {
        };
 
        const struct var_expand_test tests[] = {
+               /* syntax */
+               { .in = "%{}", .out = "", .ret = 0 },
+               {
+                       .in = "%{",
+                       .out = "syntax error, unexpected end of file, expecting "
+                              "CCBRACE or PIPE or NAME",
+                       .ret = -1
+               },
+               { .in = "hello%{}world", .out = "helloworld", .ret = 0 },
                /* basic lookup */
                { .in = "%{first}", .out = "hello", .ret = 0 },
                { .in = "%{lookup('first')}", .out = "hello", .ret = 0 },
index 9c52b3324aa978ea407d2463abe716f75ff1ef72..b9a03bbe21d777a9de5584735152f2667189f60c 100644 (file)
@@ -174,10 +174,19 @@ push_argument(VAR_EXPAND_PARSER_STYPE *state,
 
 static void make_new_program(VAR_EXPAND_PARSER_STYPE *pstate)
 {
-       struct var_expand_program *p =
+       struct var_expand_program *plast, *pp, *p =
                p_new(pstate->plist->pool, struct var_expand_program, 1);
        p->pool = pstate->plist->pool;
-       pstate->pp->next = p;
+       pp = pstate->plist;
+       plast = NULL;
+       while (pp != NULL) {
+               plast = pp;
+               pp = pp->next;
+       }
+       if (plast != NULL)
+               plast->next = p;
+       else
+               pstate->plist = p;
        pstate->p = p;
 }