BUG/MINOR: tools: Add OOM check for malloc() in indent_msg()
authorAlexander Stephan <alexander.stephan@sap.com>
Mon, 1 Sep 2025 10:01:50 +0000 (10:01 +0000)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 1 Oct 2025 14:48:34 +0000 (16:48 +0200)
This patch adds a missing out-of-memory (OOM) check after
the call to `malloc()` in `indent_msg()`. If memory
allocation fails, the function returns NULL to prevent
undefined behavior.

Co-authored-by: Christian Norbert Menges <christian.norbert.menges@sap.com>
(cherry picked from commit 26776c7b8f963299585300472a2b29ad39e47943)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 35c11b9b05b1adbfc75338a08660460458507e6f)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit ffbcd48e5af6bcfd25a14ab8bb0553e2954ff0e6)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>

src/tools.c

index a294fe3..b26ca35 100644 (file)
@@ -4559,6 +4559,8 @@ char *indent_msg(char **out, int level)
 
        needed = 1 + level * (lf + 1) + len + 1;
        p = ret = malloc(needed);
+       if (unlikely(!ret))
+               return NULL;
        in = *out;
 
        /* skip initial LFs */