Loading gethnamaddr.cpp +4 −1 Original line number Diff line number Diff line Loading @@ -388,8 +388,11 @@ nospc: int resolv_gethostbyname(const char* name, int af, hostent* hp, char* buf, size_t buflen, const android_net_context* netcontext, hostent** result, NetworkDnsEventReported* event) { getnamaddr info; if (name == nullptr || hp == nullptr) { return EAI_SYSTEM; } getnamaddr info; ResState res; res_init(&res, netcontext, event); Loading tests/resolv_integration_test.cpp +14 −1 Original line number Diff line number Diff line Loading @@ -393,7 +393,7 @@ TEST_F(ResolverTest, GetHostByName) { result = gethostbyname("nonexistent"); EXPECT_EQ(1U, GetNumQueriesForType(dns, ns_type::ns_t_a, nonexistent_host_name)); ASSERT_TRUE(result == nullptr); ASSERT_EQ(HOST_NOT_FOUND, h_errno); EXPECT_EQ(HOST_NOT_FOUND, h_errno); dns.clearQueries(); result = gethostbyname("hello"); Loading @@ -405,6 +405,19 @@ TEST_F(ResolverTest, GetHostByName) { EXPECT_TRUE(result->h_addr_list[1] == nullptr); } TEST_F(ResolverTest, GetHostByName_NULL) { // Most libc implementations would just crash on gethostbyname(NULL). Instead, Bionic // serializes the null argument over dnsproxyd, causing the server-side to crash! // This is a regression test. const char* const testcases[] = {nullptr, "", "^"}; for (const char* name : testcases) { SCOPED_TRACE(fmt::format("gethostbyname({})", name ? name : "NULL")); const hostent* result = gethostbyname(name); EXPECT_TRUE(result == nullptr); EXPECT_EQ(HOST_NOT_FOUND, h_errno); } } TEST_F(ResolverTest, GetHostByName_cnames) { constexpr char host_name[] = "host.example.com."; size_t cnamecount = 0; Loading Loading
gethnamaddr.cpp +4 −1 Original line number Diff line number Diff line Loading @@ -388,8 +388,11 @@ nospc: int resolv_gethostbyname(const char* name, int af, hostent* hp, char* buf, size_t buflen, const android_net_context* netcontext, hostent** result, NetworkDnsEventReported* event) { getnamaddr info; if (name == nullptr || hp == nullptr) { return EAI_SYSTEM; } getnamaddr info; ResState res; res_init(&res, netcontext, event); Loading
tests/resolv_integration_test.cpp +14 −1 Original line number Diff line number Diff line Loading @@ -393,7 +393,7 @@ TEST_F(ResolverTest, GetHostByName) { result = gethostbyname("nonexistent"); EXPECT_EQ(1U, GetNumQueriesForType(dns, ns_type::ns_t_a, nonexistent_host_name)); ASSERT_TRUE(result == nullptr); ASSERT_EQ(HOST_NOT_FOUND, h_errno); EXPECT_EQ(HOST_NOT_FOUND, h_errno); dns.clearQueries(); result = gethostbyname("hello"); Loading @@ -405,6 +405,19 @@ TEST_F(ResolverTest, GetHostByName) { EXPECT_TRUE(result->h_addr_list[1] == nullptr); } TEST_F(ResolverTest, GetHostByName_NULL) { // Most libc implementations would just crash on gethostbyname(NULL). Instead, Bionic // serializes the null argument over dnsproxyd, causing the server-side to crash! // This is a regression test. const char* const testcases[] = {nullptr, "", "^"}; for (const char* name : testcases) { SCOPED_TRACE(fmt::format("gethostbyname({})", name ? name : "NULL")); const hostent* result = gethostbyname(name); EXPECT_TRUE(result == nullptr); EXPECT_EQ(HOST_NOT_FOUND, h_errno); } } TEST_F(ResolverTest, GetHostByName_cnames) { constexpr char host_name[] = "host.example.com."; size_t cnamecount = 0; Loading