From eb214017fc99fa8105ddcf9e61b030f6d9e12e2b Mon Sep 17 00:00:00 2001 From: AllSeeingEyeTolledEweSew Date: Tue, 8 Dec 2020 09:16:26 +0000 Subject: [PATCH] gethostbyaddr_r: set result pointer to null on error, per specification --- src/lib/gethostbyname.c | 12 ++++++++---- tests/test_dns.c | 3 +++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/lib/gethostbyname.c b/src/lib/gethostbyname.c index b1b2183..aa4d5dd 100644 --- a/src/lib/gethostbyname.c +++ b/src/lib/gethostbyname.c @@ -310,14 +310,18 @@ LIBC_GETHOSTBYADDR_R_RET_TYPE tsocks_gethostbyaddr_r(LIBC_GETHOSTBYADDR_R_SIG) data->addr_list[1] = NULL; he->h_addr_list = data->addr_list; - if (result) { - *result = he; - } - /* Everything went good. */ ret = 0; error: + if (result) { + if (ret == 0) { + *result = he; + } else { + *result = NULL; + } + } + return ret; } diff --git a/tests/test_dns.c b/tests/test_dns.c index 7e07663..e11dcd7 100644 --- a/tests/test_dns.c +++ b/tests/test_dns.c @@ -95,6 +95,9 @@ static void test_gethostbyaddr_r_failed(void) result = gethostbyaddr_r((const void *)&addr, INET_ADDRSTRLEN, AF_INET, &ret, buf, buflen, &result_entp, &h_errno); ok(0 != result, "Impossible reverse resolve failed as desired."); + if (result_entp) { + fail("Result pointer should be NULL on failed resolve") + } } static void test_gethostbyaddr_r(const struct test_host *host)