diff --git a/src/cfgparse-global.c b/src/cfgparse-global.c index d220a2cd1..c9805a32e 100644 --- a/src/cfgparse-global.c +++ b/src/cfgparse-global.c @@ -11,6 +11,7 @@ #include #include +#include #include #include #include @@ -948,7 +949,13 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm) goto out; } chunk_destroy(&global.log_tag); - chunk_initstr(&global.log_tag, strdup(args[1])); + chunk_initlen(&global.log_tag, strdup(args[1]), strlen(args[1]), strlen(args[1])); + if (b_orig(&global.log_tag) == NULL) { + chunk_destroy(&global.log_tag); + ha_alert("parsing [%s:%d]: cannot allocate memory for '%s'.\n", file, linenum, args[0]); + err_code |= ERR_ALERT | ERR_FATAL; + goto out; + } } else if (!strcmp(args[0], "spread-checks")) { /* random time between checks (0-50) */ if (alertif_too_many_args(1, file, linenum, args, &err_code)) diff --git a/src/cfgparse-listen.c b/src/cfgparse-listen.c index cdfca5b3a..b8f379524 100644 --- a/src/cfgparse-listen.c +++ b/src/cfgparse-listen.c @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -2821,7 +2822,13 @@ stats_error_parsing: goto out; } chunk_destroy(&curproxy->log_tag); - chunk_initstr(&curproxy->log_tag, strdup(args[1])); + chunk_initlen(&curproxy->log_tag, strdup(args[1]), strlen(args[1]), strlen(args[1])); + if (b_orig(&curproxy->log_tag) == NULL) { + chunk_destroy(&curproxy->log_tag); + ha_alert("parsing [%s:%d]: cannot allocate memory for '%s'.\n", file, linenum, args[0]); + err_code |= ERR_ALERT | ERR_FATAL; + goto out; + } } else if (!strcmp(args[0], "log")) { /* "no log" or "log ..." */ if (!parse_logsrv(args, &curproxy->logsrvs, (kwm == KWM_NO), &errmsg)) { diff --git a/src/haproxy.c b/src/haproxy.c index 7458dee36..0c1dd5a97 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -1595,7 +1595,12 @@ static void init(int argc, char **argv) progname = tmp + 1; /* the process name is used for the logs only */ - chunk_initstr(&global.log_tag, strdup(progname)); + chunk_initlen(&global.log_tag, strdup(progname), strlen(progname), strlen(progname)); + if (b_orig(&global.log_tag) == NULL) { + chunk_destroy(&global.log_tag); + ha_alert("Cannot allocate memory for log_tag.\n"); + exit(EXIT_FAILURE); + } argc--; argv++; while (argc > 0) {