]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MINOR: cfgparse-global: add missing calloc() check for the global description
authorWilly Tarreau <w@1wt.eu>
Tue, 15 Sep 2026 14:37:58 +0000 (16:37 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 9 Oct 2026 07:22:33 +0000 (09:22 +0200)
The global "description" keyword passes the result of calloc() directly to
snprintf() without checking it, resulting in a crash instead of an error
message if the allocation fails.

This may be backported to all supported versions.

src/cfgparse-global.c

index 0e8624de0eb47fbd59d623672a38e91bb9fb4f2c..1d214669269586ca482f3cbad2c8c63c64c8cb4d 100644 (file)
@@ -471,6 +471,12 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm)
 
                free(global.desc);
                global.desc = d = calloc(1, len);
+               if (!d) {
+                       ha_alert("parsing [%s:%d]: cannot allocate memory for '%s'.\n",
+                                file, linenum, args[0]);
+                       err_code |= ERR_ALERT | ERR_ABORT;
+                       goto out;
+               }
 
                d += snprintf(d, global.desc + len - d, "%s", args[1]);
                for (i = 2; *args[i]; i++)