From: Frederic Marchal Date: Thu, 5 Nov 2015 20:09:31 +0000 (+0100) Subject: Prevent a segfault if a host name doesn't resolve to an IP address X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=075352778d23d67b9b736cf43a284e190189e047;p=thirdparty%2Fsarg.git Prevent a segfault if a host name doesn't resolve to an IP address If getaddrinfo fails, the linked list is not initialized. It must therefore not be freed. The error occurred when datafile was defined in sarg.conf and datafile_url was set to ip (the default value). Thanks to Evgeniy Yakushev for finding and reporting this bug. --- diff --git a/ip2name.c b/ip2name.c index 75a949c..bd5da8a 100644 --- a/ip2name.c +++ b/ip2name.c @@ -258,7 +258,7 @@ void name2ip(char *name,int name_size) #ifdef HAVE_GETADDRINFO int error; char *port; - struct addrinfo *res; + struct addrinfo *res=NULL; char *addr; addr=name; @@ -275,7 +275,7 @@ void name2ip(char *name,int name_size) error=getaddrinfo(addr,NULL,NULL,&res); if (error) { - freeaddrinfo(res); + if (res) freeaddrinfo(res); debuga(__FILE__,__LINE__,_("Cannot resolve host name %s: %s\n"),name,gai_strerror(error)); exit(EXIT_FAILURE); }