From 075352778d23d67b9b736cf43a284e190189e047 Mon Sep 17 00:00:00 2001 From: Frederic Marchal Date: Thu, 5 Nov 2015 21:09:31 +0100 Subject: [PATCH] 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. --- ip2name.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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); } -- 2.47.2