]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: cfgparse: Add OOM check for calloc() in cfg_parse_listen()
authorAlexander Stephan <alexander.stephan@sap.com>
Mon, 1 Sep 2025 09:51:19 +0000 (09:51 +0000)
committerWilly Tarreau <w@1wt.eu>
Tue, 2 Sep 2025 05:29:54 +0000 (07:29 +0200)
This commit adds a missing out-of-memory (OOM) check
after the call to `calloc()` in `cfg_parse_listen()`.
If memory allocation fails, an alert is logged, error
codes are set, and parsing is aborted to prevent
undefined behavior.

Co-authored-by: Christian Norbert Menges <christian.norbert.menges@sap.com>
src/cfgparse-listen.c

index b0d24be3abd53077d8dbfa9db58c4c2df6a51847..748ab696d2336b35c76b88289db9183fd880834d 100644 (file)
@@ -2029,6 +2029,12 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
                                        len += strlen(args[i]) + 1;
 
                                desc = d = calloc(1, len);
+                               if (unlikely(!d)) {
+                                       ha_alert("parsing [%s:%d]: '%s %s' : memory allocation failed\n",
+                                                        file, linenum, args[0], args[1]);
+                                       err_code |= ERR_ALERT | ERR_FATAL;
+                                       goto out;
+                               }
 
                                d += snprintf(d, desc + len - d, "%s", args[2]);
                                for (i = 3; *args[i]; i++)