BUG/MINOR: log-format: uncatched memory allocation functions

Some return code of memory allocation functions are not tested.
This patch fix theses checks.
This commit is contained in:
Thierry FOURNIER / OZON.IO 2016-11-22 23:24:10 +01:00 committed by Willy Tarreau
parent df4399fcb6
commit 9cbfef2455

View File

@ -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) { strncmp(var, logformat_keywords[j].name, var_len) == 0) {
if (logformat_keywords[j].mode != PR_MODE_HTTP || curproxy->mode == PR_MODE_HTTP) { if (logformat_keywords[j].mode != PR_MODE_HTTP || curproxy->mode == PR_MODE_HTTP) {
node = calloc(1, sizeof(*node)); node = calloc(1, sizeof(*node));
if (!node) {
Alert("Out of memory error.\n");
return 0;
}
node->type = logformat_keywords[j].type; node->type = logformat_keywords[j].type;
node->options = *defoptions; node->options = *defoptions;
if (arg_len) { 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 */ if (type == LF_TEXT) { /* type text */
struct logformat_node *node = calloc(1, sizeof(*node)); struct logformat_node *node = calloc(1, sizeof(*node));
if (!node) {
Alert("Out of memory error.\n");
return 0;
}
str = calloc(1, end - start + 1); str = calloc(1, end - start + 1);
strncpy(str, start, end - start); strncpy(str, start, end - start);
str[end - start] = '\0'; 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); LIST_ADDQ(list_format, &node->list);
} else if (type == LF_SEPARATOR) { } else if (type == LF_SEPARATOR) {
struct logformat_node *node = calloc(1, sizeof(*node)); struct logformat_node *node = calloc(1, sizeof(*node));
if (!node) {
Alert("Out of memory error.\n");
return 0;
}
node->type = LOG_FMT_SEPARATOR; node->type = LOG_FMT_SEPARATOR;
LIST_ADDQ(list_format, &node->list); 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)); node = calloc(1, sizeof(*node));
if (!node) {
Alert("Out of memory error.\n");
return 0;
}
node->type = LOG_FMT_EXPR; node->type = LOG_FMT_EXPR;
node->expr = expr; node->expr = expr;
node->options = options; node->options = options;
@ -503,6 +519,10 @@ void parse_logformat_string(const char *fmt, struct proxy *curproxy, struct list
struct logformat_node *tmplf, *back; struct logformat_node *tmplf, *back;
sp = str = backfmt = strdup(fmt); sp = str = backfmt = strdup(fmt);
if (!str) {
Alert("Out of memory error.\n");
return 0;
}
curproxy->to_log |= LW_INIT; curproxy->to_log |= LW_INIT;
/* flush the list first. */ /* flush the list first. */