From: Greg Hudson Date: Tue, 3 Mar 2020 17:27:02 +0000 (-0500) Subject: Fix null dereference qualifying short hostnames X-Git-Tag: krb5-1.19-beta1~109 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F1045%2Fhead;p=thirdparty%2Fkrb5.git Fix null dereference qualifying short hostnames Fix the dnsglue.c PRIMARY_DOMAIN macro not to call strdup() with a null pointer if no DNS search path is configured. ticket: 8881 tags: pullup target_version: 1.18-next --- diff --git a/src/lib/krb5/os/dnsglue.c b/src/lib/krb5/os/dnsglue.c index e35ca9d76c..0cd213fdd7 100644 --- a/src/lib/krb5/os/dnsglue.c +++ b/src/lib/krb5/os/dnsglue.c @@ -91,7 +91,7 @@ static int initparse(struct krb5int_dns_state *); #define DECLARE_HANDLE(h) struct __res_state h #define INIT_HANDLE(h) (memset(&h, 0, sizeof(h)), res_ninit(&h) == 0) #define SEARCH(h, n, c, t, a, l) res_nsearch(&h, n, c, t, a, l) -#define PRIMARY_DOMAIN(h) strdup(h.dnsrch[0]) +#define PRIMARY_DOMAIN(h) ((h.dnsrch[0] == NULL) ? NULL : strdup(h.dnsrch[0])) #if HAVE_RES_NDESTROY #define DESTROY_HANDLE(h) res_ndestroy(&h) #else @@ -104,7 +104,8 @@ static int initparse(struct krb5int_dns_state *); #define DECLARE_HANDLE(h) #define INIT_HANDLE(h) (res_init() == 0) #define SEARCH(h, n, c, t, a, l) res_search(n, c, t, a, l) -#define PRIMARY_DOMAIN(h) strdup(_res.defdname) +#define PRIMARY_DOMAIN(h) \ + ((_res.defdname == NULL) ? NULL : strdup(_res.defdname)) #define DESTROY_HANDLE(h) #endif