]> granicus.if.org Git - neomutt/commitdiff
Prevent null pointer exception for h->ai_canonname
authorAthanasios Douitsis <aduitsis@gmail.com>
Sat, 18 Feb 2017 21:30:27 +0000 (21:30 +0000)
committerAthanasios Douitsis <aduitsis@gmail.com>
Sat, 18 Feb 2017 21:30:27 +0000 (21:30 +0000)
The getaddrinfo call in line 54 sets &h to a struct addrinfo. If a
canonical name cannot be found for the node argument of getaddrinfo,
h->ai_canonname is set to NULL. In that case, the strchr call in line
58 can lead to segfault. This behavior was observed on a macos sierra
while the hostname was 192.168.1.3 (unfortunately this happens quite
often in macos).

The fix is simple, just check h->ai_canonname for the NULL value.

getdomain.c

index 15803afb37fb553de650295d2ba1e79d600d21e7..2190d76e21a8605925c21661e0d2bf88147e0e00 100644 (file)
@@ -55,7 +55,7 @@ int getdnsdomainname (char *d, size_t len)
     ret = -1;
   else
   {
-    if (!(p = strchr(h->ai_canonname, '.')))
+    if (!h->ai_canonname || !(p = strchr(h->ai_canonname, '.')))
       ret = -1;
     else
     {