]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Prevent a segfault if a host name doesn't resolve to an IP address
authorFrederic Marchal <fmarchal@users.sourceforge.net>
Thu, 5 Nov 2015 20:09:31 +0000 (21:09 +0100)
committerFrederic Marchal <fmarchal@users.sourceforge.net>
Thu, 5 Nov 2015 20:09:31 +0000 (21:09 +0100)
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

index 75a949cd2a86d2a63474916aa0e034ade9daed7f..bd5da8ada7710b80fd00eb4c8fcb45ca7999ed2c 100644 (file)
--- 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);
        }