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)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 1 Oct 2025 14:48:34 +0000 (16:48 +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>
(cherry picked from commit 73f9a75894c660dd034439e0bc343aa00489dbc9)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 8a4bc5b7fc474e1b7178f8cf25428077c3fb7c34)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit e9065b50776baca3c6d475539b89b2e7ab994b7c)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>

src/cfgparse-listen.c

index d3d38c6..4ad4016 100644 (file)
@@ -1862,6 +1862,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++)