From 53f86fb288eec10113aaab3412544b5f0c03db8b Mon Sep 17 00:00:00 2001 From: Ken Raeburn Date: Wed, 21 Jun 2006 00:28:21 +0000 Subject: [PATCH] (GET_HOST_BY_NAME, GET_HOST_BY_ADDR) [GETHOSTBYNAME_RETURNS_INT]: Test the output hostent pointer as an additional way of checking for errors. Original patch from Nalin Dahyabhai, needed some tweaking to fit in current sources, especially as updated in ticket 3911. ticket: 2759 tags: pullup git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@18183 dc483132-0cff-0310-8789-dd5450dbe970 --- src/util/support/fake-addrinfo.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/util/support/fake-addrinfo.c b/src/util/support/fake-addrinfo.c index a622302b8..cdc2fdd04 100644 --- a/src/util/support/fake-addrinfo.c +++ b/src/util/support/fake-addrinfo.c @@ -200,11 +200,12 @@ typedef struct { } GET_HOST_TMP; #define GET_HOST_BY_NAME(NAME, HP, ERR, TMP) \ { \ - struct hostent *my_hp; \ - int my_h_err; \ - (HP) = (gethostbyname_r((NAME), &TMP.ent, \ - TMP.buf, sizeof (TMP.buf), &TMP.hp, \ - &my_h_err) \ + struct hostent *my_hp = NULL; \ + int my_h_err, my_ret; \ + my_ret = gethostbyname_r((NAME), &TMP.ent, \ + TMP.buf, sizeof (TMP.buf), &TMP.hp, \ + &my_h_err); \ + (HP) = (((my_ret != 0) || (TMP.hp != &TMP.ent)) \ ? 0 \ : &TMP.ent); \ (ERR) = my_h_err; \ @@ -212,10 +213,11 @@ typedef struct { #define GET_HOST_BY_ADDR(ADDR, ADDRLEN, FAMILY, HP, ERR, TMP) \ { \ struct hostent *my_hp; \ - int my_h_err; \ - (HP) = (gethostbyaddr_r((ADDR), (ADDRLEN), (FAMILY), &TMP.ent, \ - TMP.buf, sizeof (TMP.buf), &my_hp, \ - &my_h_err) \ + int my_h_err, my_ret; \ + my_ret = gethostbyaddr_r((ADDR), (ADDRLEN), (FAMILY), &TMP.ent, \ + TMP.buf, sizeof (TMP.buf), &my_hp, \ + &my_h_err); \ + (HP) = (((my_ret != 0) || (TMP.hp != &TMP.ent)) \ ? 0 \ : &TMP.ent); \ (ERR) = my_h_err; \ -- 2.26.2