mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-21 13:51:26 +02:00
BUG/MINOR: log: Add OOM checks for calloc() and malloc() in logformat parser and dup_logger()
This patch adds missing out-of-memory (OOM) checks after calls to `calloc()` and `malloc()` in the logformat parser and the `dup_logger()` function. If memory allocation fails, an error is reported or NULL is returned, preventing undefined behavior in low-memory conditions. Co-authored-by: Christian Norbert Menges <christian.norbert.menges@sap.com>
This commit is contained in:
parent
fbd0fb20a2
commit
22ac1f5ee9
@ -573,11 +573,11 @@ int add_to_logformat_list(char *start, char *end, int type, struct lf_expr *lf_e
|
||||
|
||||
if (type == LF_TEXT) { /* type text */
|
||||
struct logformat_node *node = calloc(1, sizeof(*node));
|
||||
if (!node) {
|
||||
str = calloc(1, end - start + 1);
|
||||
if (unlikely(!node || !str)) {
|
||||
memprintf(err, "out of memory error");
|
||||
return 0;
|
||||
}
|
||||
str = calloc(1, end - start + 1);
|
||||
strncpy(str, start, end - start);
|
||||
str[end - start] = '\0';
|
||||
node->arg = str;
|
||||
@ -1558,7 +1558,8 @@ struct logger *dup_logger(struct logger *def)
|
||||
|
||||
BUG_ON(def->flags & LOGGER_FL_RESOLVED);
|
||||
cpy = malloc(sizeof(*cpy));
|
||||
|
||||
if (unlikely(!cpy))
|
||||
return NULL;
|
||||
/* copy everything that can be easily copied */
|
||||
memcpy(cpy, def, sizeof(*cpy));
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user