tests: Check that gethostbyname_r() zeros return values
authorAndreas Schneider <asn@samba.org>
Thu, 19 Mar 2020 08:53:30 +0000 (09:53 +0100)
committerAndreas Schneider <asn@samba.org>
Thu, 19 Mar 2020 09:03:10 +0000 (10:03 +0100)
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Alexander Bokovoy <ab@samba.org>
Reviewed-by: Samuel Cabrero <scabrero@suse.de>
tests/test_gethostby_name_addr.c

index cb55c06b3a8335a645526311bec2070f321d483a..c9f459444288a40fefc7cfad347eb53661b47fdd 100644 (file)
@@ -247,6 +247,31 @@ static void test_nwrap_gethostbyname_r(void **state)
 
        assert_string_equal(ip, "127.0.0.11");
 }
+
+static void test_nwrap_gethostbyname_r_null(void **state)
+{
+       char buf[2];
+       struct hostent hb, *he;
+       int herr = 0;
+       int rc;
+
+       (void) state; /* unused */
+
+       buf[0] = 'A';
+       buf[1] = '\0';
+
+       /* Check that the returned buffer is zeroed */
+       rc = gethostbyname_r("wurst",
+                            &hb,
+                            buf, sizeof(buf),
+                            &he,
+                            &herr);
+       assert_int_equal(rc, ENOENT);
+       assert_null(he);
+       assert_null(hb.h_name);
+       assert_null(hb.h_addr_list);
+       assert_string_equal(buf, "");
+}
 #endif
 
 #ifdef HAVE_GETHOSTBYADDR_R
@@ -293,6 +318,7 @@ int main(void) {
                cmocka_unit_test(test_nwrap_gethostbyaddr),
 #ifdef HAVE_GETHOSTBYNAME_R
                cmocka_unit_test(test_nwrap_gethostbyname_r),
+               cmocka_unit_test(test_nwrap_gethostbyname_r_null),
 #endif
 #ifdef HAVE_GETHOSTBYADDR_R
                cmocka_unit_test(test_nwrap_gethostbyaddr_r),