Skip to content

Commit 73f9a75

Browse files
alexanderstephanGarfield96
authored andcommitted
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>
1 parent c3e69cf commit 73f9a75

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

src/cfgparse-listen.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2029,6 +2029,12 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
20292029
len += strlen(args[i]) + 1;
20302030

20312031
desc = d = calloc(1, len);
2032+
if (unlikely(!d)) {
2033+
ha_alert("parsing [%s:%d]: '%s %s' : memory allocation failed\n",
2034+
file, linenum, args[0], args[1]);
2035+
err_code |= ERR_ALERT | ERR_FATAL;
2036+
goto out;
2037+
}
20322038

20332039
d += snprintf(d, desc + len - d, "%s", args[2]);
20342040
for (i = 3; *args[i]; i++)

0 commit comments

Comments
 (0)