changeset: 6940:943b281abfbb user: Athanasios Douitsis <aduit...@gmail.com> date: Sat Feb 18 21:30:27 2017 +0000 link: http://dev.mutt.org/hg/mutt/rev/943b281abfbb
Prevent null pointer exception for h->ai_canonname 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. diffs (12 lines): diff -r 9b7780b48f47 -r 943b281abfbb getdomain.c --- a/getdomain.c Fri Feb 17 20:02:46 2017 -0800 +++ b/getdomain.c Sat Feb 18 21:30:27 2017 +0000 @@ -55,7 +55,7 @@ ret = -1; else { - if (!(p = strchr(h->ai_canonname, '.'))) + if (!h->ai_canonname || !(p = strchr(h->ai_canonname, '.'))) ret = -1; else {