From: Eric Salama Date: Fri, 13 Nov 2020 14:56:36 +0000 (+0100) Subject: MINOR: cfgparse: tighten the scope of newnameserver variable, free it on error. X-Git-Tag: v2.4-dev1~44 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9139ec34ed7aae4fe63926ca5c87a5b32b376488;p=thirdparty%2Fhaproxy.git MINOR: cfgparse: tighten the scope of newnameserver variable, free it on error. This should fix issue GH #931. Also remove a misleading comment. This commit can be backported as far as 1.9 --- diff --git a/src/cfgparse.c b/src/cfgparse.c index 4d3c8ad554..f1d5a41b28 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -931,7 +931,6 @@ out: int cfg_parse_resolvers(const char *file, int linenum, char **args, int kwm) { static struct dns_resolvers *curr_resolvers = NULL; - struct dns_nameserver *newnameserver = NULL; const char *err; int err_code = 0; char *errmsg = NULL; @@ -992,6 +991,7 @@ int cfg_parse_resolvers(const char *file, int linenum, char **args, int kwm) HA_SPIN_INIT(&curr_resolvers->lock); } else if (strcmp(args[0], "nameserver") == 0) { /* nameserver definition */ + struct dns_nameserver *newnameserver = NULL; struct sockaddr_storage *sk; int port1, port2; @@ -1043,6 +1043,7 @@ int cfg_parse_resolvers(const char *file, int linenum, char **args, int kwm) newnameserver->addr = *sk; } else if (strcmp(args[0], "parse-resolv-conf") == 0) { + struct dns_nameserver *newnameserver = NULL; const char *whitespace = "\r\n\t "; char *resolv_line = NULL; int resolv_linenum = 0; @@ -1131,6 +1132,7 @@ int cfg_parse_resolvers(const char *file, int linenum, char **args, int kwm) if (newnameserver->conf.file == NULL) { ha_alert("parsing [/etc/resolv.conf:%d] : out of memory.\n", resolv_linenum); err_code |= ERR_ALERT | ERR_FATAL; + free(newnameserver); goto resolv_out; } @@ -1138,6 +1140,8 @@ int cfg_parse_resolvers(const char *file, int linenum, char **args, int kwm) if (newnameserver->id == NULL) { ha_alert("parsing [/etc/resolv.conf:%d] : out of memory.\n", resolv_linenum); err_code |= ERR_ALERT | ERR_FATAL; + free((char *)newnameserver->conf.file); + free(newnameserver); goto resolv_out; } @@ -1287,7 +1291,7 @@ resolv_out: err_code |= ERR_ALERT | ERR_FATAL; goto out; } - } /* neither "nameserver" nor "resolvers" */ + } else if (*args[0] != 0) { ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection); err_code |= ERR_ALERT | ERR_FATAL;