From 9a72726ec528995c7bf5ffaaada3fa0df23ef93f Mon Sep 17 00:00:00 2001
From: Alexander Stephan <alexander.stephan@sap.com>
Date: Mon, 1 Sep 2025 09:51:19 +0000
Subject: [PATCH 4/6] BUG/MINOR: cfgparse: Add OOM check for calloc() in
 cfg_parse_listen()

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 | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/cfgparse-listen.c b/src/cfgparse-listen.c
index 07bb05012..4e74a20d6 100644
--- a/src/cfgparse-listen.c
+++ b/src/cfgparse-listen.c
@@ -2020,6 +2020,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++)
-- 
2.35.3

