]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
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)
committerWilly Tarreau <w@1wt.eu>
Tue, 2 Sep 2025 05:29:54 +0000 (07:29 +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>
src/tools.c

index 4507564bce86ac34a40706fdc8a02f3f18e51904..1615ef2ae0341686cefa3ca5f1eaa9fd13cfb2a8 100644 (file)
@@ -4689,6 +4689,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 */