summaryrefslogtreecommitdiffstats
path: root/getdomain.c
diff options
context:
space:
mode:
authorAthanasios Douitsis <aduitsis@gmail.com>2017-02-18 21:30:27 +0000
committerAthanasios Douitsis <aduitsis@gmail.com>2017-02-18 21:30:27 +0000
commit473a6a66493ce662318bc15db14e524b8bf023fe (patch)
tree8ded2e8f5c9f7e453e23d3fddd628df77a51d14b /getdomain.c
parent5558bda5f1eef1e200822060c601e58e3f026a29 (diff)
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.
Diffstat (limited to 'getdomain.c')
-rw-r--r--getdomain.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/getdomain.c b/getdomain.c
index 15803afb..2190d76e 100644
--- a/getdomain.c
+++ b/getdomain.c
@@ -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
{