Merge "Replace android::sp by std::shared_ptr and drop the libutils dependency" into main
diff --git a/DnsProxyListener.cpp b/DnsProxyListener.cpp
index e70ddb4..8064aef 100644
--- a/DnsProxyListener.cpp
+++ b/DnsProxyListener.cpp
@@ -685,7 +685,8 @@
InitFn ADnsHelper_init = reinterpret_cast<InitFn>(dlsym(handle, "ADnsHelper_init"));
if (!ADnsHelper_init) {
LOG(ERROR) << __func__ << ": " << dlerror();
- abort();
+ // TODO: Change to abort() when NDK is finalized
+ return nullptr;
}
const int ret = (*ADnsHelper_init)();
if (ret) {
@@ -697,7 +698,8 @@
reinterpret_cast<IsUidBlockedFn>(dlsym(handle, "ADnsHelper_isUidNetworkingBlocked"));
if (!f) {
LOG(ERROR) << __func__ << ": " << dlerror();
- abort();
+ // TODO: Change to abort() when NDK is finalized
+ return nullptr;
}
return f;
}
diff --git a/sethostent.cpp b/sethostent.cpp
index a9b0de6..55b8c8b 100644
--- a/sethostent.cpp
+++ b/sethostent.cpp
@@ -69,6 +69,8 @@
char* aliases[MAXALIASES];
char* addr_ptrs[MAXADDRS];
+ // TODO: Wrap the 'hf' into a RAII class or std::shared_ptr and modify the
+ // sethostent_r()/endhostent_r() to get rid of manually endhostent_r(&hf) everywhere.
FILE* hf = NULL;
sethostent_r(&hf);
if (hf == NULL) {
@@ -80,6 +82,7 @@
}
if ((ptr = buf = (char*) malloc(len = info->buflen)) == NULL) {
+ endhostent_r(&hf);
return EAI_MEMORY;
}
@@ -103,6 +106,7 @@
if (hp->h_name == nullptr) {
free(buf);
+ endhostent_r(&hf);
return EAI_FAIL;
}
const char* h_name = hp->h_name;
@@ -131,6 +135,7 @@
if (num >= MAXADDRS) goto nospc;
if (hp->h_addr_list[0] == nullptr) {
free(buf);
+ endhostent_r(&hf);
return EAI_FAIL;
}
const char* addr = hp->h_addr_list[0];
@@ -185,6 +190,7 @@
free(buf);
return 0;
nospc:
+ endhostent_r(&hf);
free(buf);
return EAI_MEMORY;
}
diff --git a/tests/resolv_integration_test.cpp b/tests/resolv_integration_test.cpp
index ef2bf1e..d3e0c59 100644
--- a/tests/resolv_integration_test.cpp
+++ b/tests/resolv_integration_test.cpp
@@ -4833,7 +4833,7 @@
// DOT_SERVER_UNRESPONSIVE_TIME_MS, DoT queries should timeout.
TEST_F(ResolverTest, QueryTlsServerTimeout) {
constexpr int DOT_SERVER_UNRESPONSIVE_TIME_MS = 2000;
- constexpr int TIMING_TOLERANCE_MS = 200;
+ constexpr int TIMING_TOLERANCE_MS = 500;
constexpr char hostname1[] = "query1.example.com.";
const std::vector<DnsRecord> records = {
{hostname1, ns_type::ns_t_a, "1.2.3.4"},
diff --git a/tests/resolv_private_dns_test.cpp b/tests/resolv_private_dns_test.cpp
index c9b8f46..943a610 100644
--- a/tests/resolv_private_dns_test.cpp
+++ b/tests/resolv_private_dns_test.cpp
@@ -575,14 +575,14 @@
// DataSaver information is only meaningful after V.
// TODO: Add 'else' to check that DNS queries are not blocked before V.
if (android::modules::sdklevel::IsAtLeastV()) {
- expectQueriesAreBlocked();
+ EXPECT_NO_FAILURE(expectQueriesAreBlocked());
}
} else {
// Block network access by setting UID firewall rules.
ScopeBlockedUIDRule scopeBlockUidRule(mDnsClient.netdService(), TEST_UID);
- expectQueriesAreBlocked();
+ EXPECT_NO_FAILURE(expectQueriesAreBlocked());
}
- expectQueries(0 /* dns */, 0 /* dot */, 0 /* doh */);
+ EXPECT_NO_FAILURE(expectQueries(0 /* dns */, 0 /* dot */, 0 /* doh */));
}
}