]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: log-format: uncatched memory allocation functions
authorThierry FOURNIER / OZON.IO <thierry.fournier@ozon.io>
Tue, 22 Nov 2016 22:24:10 +0000 (23:24 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 24 Nov 2016 17:54:25 +0000 (18:54 +0100)
Some return code of memory allocation functions are not tested.
This patch fix theses checks.

src/log.c

index 12329888130eb35fda93b08d019b2ec83abc4c90..4f7d78827abd7f72e1c938d77241631469a60449 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -351,6 +351,10 @@ int parse_logformat_var(char *arg, int arg_len, char *var, int var_len, struct p
                    strncmp(var, logformat_keywords[j].name, var_len) == 0) {
                        if (logformat_keywords[j].mode != PR_MODE_HTTP || curproxy->mode == PR_MODE_HTTP) {
                                node = calloc(1, sizeof(*node));
+                               if (!node) {
+                                       Alert("Out of memory error.\n");
+                                       return 0;
+                               }
                                node->type = logformat_keywords[j].type;
                                node->options = *defoptions;
                                if (arg_len) {
@@ -408,6 +412,10 @@ void add_to_logformat_list(char *start, char *end, int type, struct list *list_f
 
        if (type == LF_TEXT) { /* type text */
                struct logformat_node *node = calloc(1, sizeof(*node));
+               if (!node) {
+                       Alert("Out of memory error.\n");
+                       return 0;
+               }
                str = calloc(1, end - start + 1);
                strncpy(str, start, end - start);
                str[end - start] = '\0';
@@ -416,6 +424,10 @@ void add_to_logformat_list(char *start, char *end, int type, struct list *list_f
                LIST_ADDQ(list_format, &node->list);
        } else if (type == LF_SEPARATOR) {
                struct logformat_node *node = calloc(1, sizeof(*node));
+               if (!node) {
+                       Alert("Out of memory error.\n");
+                       return 0;
+               }
                node->type = LOG_FMT_SEPARATOR;
                LIST_ADDQ(list_format, &node->list);
        }
@@ -447,6 +459,10 @@ void add_sample_to_logformat_list(char *text, char *arg, int arg_len, struct pro
        }
 
        node = calloc(1, sizeof(*node));
+       if (!node) {
+               Alert("Out of memory error.\n");
+               return 0;
+       }
        node->type = LOG_FMT_EXPR;
        node->expr = expr;
        node->options = options;
@@ -503,6 +519,10 @@ void parse_logformat_string(const char *fmt, struct proxy *curproxy, struct list
        struct logformat_node *tmplf, *back;
 
        sp = str = backfmt = strdup(fmt);
+       if (!str) {
+               Alert("Out of memory error.\n");
+               return 0;
+       }
        curproxy->to_log |= LW_INIT;
 
        /* flush the list first. */