Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1a4efc60 authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 11227258 from d26b2db2 to 24Q2-release

Change-Id: Icf5e454307dabd0de2ad125d451fd22193496518
parents 80541256 d26b2db2
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -69,6 +69,8 @@ int _hf_gethtbyname2(const char* name, int af, getnamaddr* info) {
    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 @@ int _hf_gethtbyname2(const char* name, int af, getnamaddr* info) {
    }

    if ((ptr = buf = (char*) malloc(len = info->buflen)) == NULL) {
        endhostent_r(&hf);
        return EAI_MEMORY;
    }

@@ -103,6 +106,7 @@ int _hf_gethtbyname2(const char* name, int af, getnamaddr* info) {

        if (hp->h_name == nullptr) {
            free(buf);
            endhostent_r(&hf);
            return EAI_FAIL;
        }
        const char* h_name = hp->h_name;
@@ -131,6 +135,7 @@ int _hf_gethtbyname2(const char* name, int af, getnamaddr* info) {
        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 @@ int _hf_gethtbyname2(const char* name, int af, getnamaddr* info) {
    free(buf);
    return 0;
nospc:
    endhostent_r(&hf);
    free(buf);
    return EAI_MEMORY;
}
+56 −57
Original line number Diff line number Diff line
@@ -4827,20 +4827,35 @@ TEST_F(ResolverTest, ConnectTlsServerTimeout_ConcurrentQueries) {
    }
}

// Tests that the DoT query timeout is configurable via the feature flag "dot_query_timeout_ms".
// The test DoT server is configured to postpone DNS queries for DOT_SERVER_UNRESPONSIVE_TIME_MS
// (2s). If the feature flag is set to a positive value smaller than
// DOT_SERVER_UNRESPONSIVE_TIME_MS, DoT queries should timeout.
TEST_F(ResolverTest, QueryTlsServerTimeout) {
    constexpr uint32_t cacheFlag = ANDROID_RESOLV_NO_CACHE_LOOKUP;
    constexpr int INFINITE_QUERY_TIMEOUT = -1;
    constexpr int DOT_SERVER_UNRESPONSIVE_TIME_MS = 5000;
    constexpr int DOT_SERVER_UNRESPONSIVE_TIME_MS = 2000;
    constexpr int TIMING_TOLERANCE_MS = 200;
    constexpr char hostname1[] = "query1.example.com.";
    constexpr char hostname2[] = "query2.example.com.";
    const std::vector<DnsRecord> records = {
            {hostname1, ns_type::ns_t_a, "1.2.3.4"},
            {hostname2, ns_type::ns_t_a, "1.2.3.5"},
    };

    for (const int queryTimeoutMs : {INFINITE_QUERY_TIMEOUT, 1000}) {
        for (const std::string_view dnsMode : {"OPPORTUNISTIC", "STRICT"}) {
            SCOPED_TRACE(fmt::format("testConfig: [{}] [{}]", dnsMode, queryTimeoutMs));
    static const struct TestConfig {
        std::string dnsMode;
        int queryTimeoutMs;
        int expectResultTimedOut;
        int expectedTimeTakenMs;
    } testConfigs[] = {
            // clang-format off
            {"OPPORTUNISTIC",   -1, false, DOT_SERVER_UNRESPONSIVE_TIME_MS},
            {"OPPORTUNISTIC", 1000, false,                            1000},
            {"STRICT",          -1, false, DOT_SERVER_UNRESPONSIVE_TIME_MS},
            // `expectResultTimedOut` is true in the following testcase because in strict mode
            // DnsResolver doesn't try Do53 servers after the DoT query is timed out.
            {"STRICT",        1000,  true,                            1000},
            // clang-format on
    };
    for (const auto& config : testConfigs) {
        SCOPED_TRACE(fmt::format("testConfig: [{}] [{}]", config.dnsMode, config.queryTimeoutMs));

        const std::string addr = getUniqueIPv4Address();
        test::DNSResponder dns(addr);
@@ -4848,7 +4863,7 @@ TEST_F(ResolverTest, QueryTlsServerTimeout) {
        test::DnsTlsFrontend tls(addr, "853", addr, "53");
        ASSERT_TRUE(tls.startServer());

            ScopedSystemProperties sp(kDotQueryTimeoutMsFlag, std::to_string(queryTimeoutMs));
        ScopedSystemProperties sp(kDotQueryTimeoutMsFlag, std::to_string(config.queryTimeoutMs));

        // Don't skip unusable DoT servers and disable revalidation for this test.
        ScopedSystemProperties sp2(kDotXportUnusableThresholdFlag, "-1");
@@ -4858,46 +4873,30 @@ TEST_F(ResolverTest, QueryTlsServerTimeout) {
        auto parcel = DnsResponderClient::GetDefaultResolverParamsParcel();
        parcel.servers = {addr};
        parcel.tlsServers = {addr};
            if (dnsMode == "STRICT") parcel.tlsName = kDefaultPrivateDnsHostName;
        if (config.dnsMode == "STRICT") parcel.tlsName = kDefaultPrivateDnsHostName;

        ASSERT_TRUE(mDnsClient.SetResolversFromParcel(parcel));
        EXPECT_TRUE(WaitForPrivateDnsValidation(tls.listen_address(), true));
        EXPECT_TRUE(tls.waitForQueries(1));
        tls.clearQueries();

            // Set the DoT server to be unresponsive to DNS queries until either it receives
            // 2 queries or 5s later.
            tls.setDelayQueries(2);
        // Set the DoT server to be unresponsive to DNS queries for
        // `DOT_SERVER_UNRESPONSIVE_TIME_MS` ms.
        tls.setDelayQueries(999);
        tls.setDelayQueriesTimeout(DOT_SERVER_UNRESPONSIVE_TIME_MS);

            // First query.
        // Send a DNS query, and then check the result and the response time.
        Stopwatch s;
            int fd = resNetworkQuery(TEST_NETID, hostname1, ns_c_in, ns_t_a, cacheFlag);
            if (dnsMode == "STRICT" && queryTimeoutMs != INFINITE_QUERY_TIMEOUT) {
        int fd = resNetworkQuery(TEST_NETID, hostname1, ns_c_in, ns_t_a,
                                 ANDROID_RESOLV_NO_CACHE_LOOKUP);
        if (config.expectResultTimedOut) {
            expectAnswersNotValid(fd, -ETIMEDOUT);
        } else {
            expectAnswersValid(fd, AF_INET, "1.2.3.4");
        }

            // Besides checking the result of the query, check how much time the
            // resolver processed the query.
            int timeTakenMs = s.getTimeAndResetUs() / 1000;
            const int expectedTimeTakenMs = (queryTimeoutMs == INFINITE_QUERY_TIMEOUT)
                                                    ? DOT_SERVER_UNRESPONSIVE_TIME_MS
                                                    : queryTimeoutMs;
            EXPECT_GE(timeTakenMs, expectedTimeTakenMs);
            EXPECT_LE(timeTakenMs, expectedTimeTakenMs + 1000);

            // Second query.
            tls.setDelayQueries(1);
            fd = resNetworkQuery(TEST_NETID, hostname2, ns_c_in, ns_t_a, cacheFlag);
            expectAnswersValid(fd, AF_INET, "1.2.3.5");

            // Also check how much time the resolver processed the query.
            timeTakenMs = s.timeTakenUs() / 1000;
            EXPECT_LE(timeTakenMs, 500);
            EXPECT_TRUE(tls.waitForQueries(2));
        }
        const int timeTakenMs = s.getTimeAndResetUs() / 1000;
        EXPECT_NEAR(config.expectedTimeTakenMs, timeTakenMs, TIMING_TOLERANCE_MS);
        EXPECT_TRUE(tls.waitForQueries(1));
    }
}

+6 −1
Original line number Diff line number Diff line
@@ -571,7 +571,12 @@ TEST_P(TransportParameterizedTest, BlockDnsQuery) {
            // Block network access by enabling data saver.
            ScopedSetDataSaverByBPF scopedSetDataSaverByBPF(true);
            ScopedChangeUID scopedChangeUID(TEST_UID);

            // 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();
            }
        } else {
            // Block network access by setting UID firewall rules.
            ScopeBlockedUIDRule scopeBlockUidRule(mDnsClient.netdService(), TEST_UID);
+3 −0
Original line number Diff line number Diff line
@@ -107,6 +107,8 @@ NetworkDnsEventReported fromNetworkDnsEventReportedStr(const std::string& str) {
                event.set_private_dns_modes(static_cast<PrivateDnsModes>(value));
            } else if (protoField[1] == "sampling_rate_denom" && ParseInt(protoField[2], &value)) {
                event.set_sampling_rate_denom(value);
            } else if (protoField[1] == "uid" && ParseInt(protoField[2], &value)) {
                event.set_uid(value);
            }
        }
        // Parsing each field of the proto DnsQueryEvent
@@ -169,6 +171,7 @@ void PrintTo(const NetworkDnsEventReported& event, std::ostream* os) {
    *os << "  network_type: " << event.network_type() << "\n";
    *os << "  private_dns_modes: " << event.private_dns_modes() << "\n";
    *os << "  dns_query_event_size: " << event.dns_query_events().dns_query_event_size() << "\n";
    *os << "  uid: " << event.uid() << "\n";
    *os << "}";
}

+3 −1
Original line number Diff line number Diff line
@@ -120,7 +120,9 @@ MATCHER_P(NetworkDnsEventEq, other, "") {
                    */
                    ::testing::Property("dns_query_events",
                                        &android::net::NetworkDnsEventReported::dns_query_events,
                                        DnsQueryEventsEq(other.dns_query_events()))),
                                        DnsQueryEventsEq(other.dns_query_events())),
                    ::testing::Property("uid", &android::net::NetworkDnsEventReported::uid,
                                        ::testing::Eq(other.uid()))),
            arg, result_listener);
}

Loading