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

Commit 7803769c authored by Bernie Innocenti's avatar Bernie Innocenti Committed by Gerrit Code Review
Browse files

Merge "Explicitly allocate ResState on the call stack"

parents 059357ce 08487119
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -50,7 +50,6 @@ cc_library {
        "res_mkquery.cpp",
        "res_query.cpp",
        "res_send.cpp",
        "res_state.cpp",
        "res_stats.cpp",
        "Dns64Configuration.cpp",
        "DnsProxyListener.cpp",
+1 −0
Original line number Diff line number Diff line
[Builtin Hooks]
clang_format = true
commit_msg_test_field = false

[Builtin Hooks Options]
clang_format = --commit ${PREUPLOAD_COMMIT} --style file --extensions c,h,cc,cpp
+6 −11
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@
#include <android-base/logging.h>

#include "netd_resolv/resolv.h"
#include "res_init.h"
#include "resolv_cache.h"
#include "resolv_private.h"

@@ -1445,18 +1446,11 @@ static int dns_getaddrinfo(const char* name, const addrinfo* pai,
            return EAI_FAMILY;
    }

    res_state res = res_get_state();
    if (!res) return EAI_MEMORY;

    /* this just sets our netid val in the thread private data so we don't have to
     * modify the api's all the way down to res_send.c's res_nsend.  We could
     * fully populate the thread private data here, but if we get down there
     * and have a cache hit that would be wasted, so we do the rest there on miss
     */
    res_setnetcontext(res, netcontext, event);
    ResState res;
    res_init(&res, netcontext, event);

    int he;
    if (res_searchN(name, &q, res, &he) < 0) {
    if (res_searchN(name, &q, &res, &he) < 0) {
        // Return h_errno (he) to catch more detailed errors rather than EAI_NODATA.
        // Note that res_searchN() doesn't set the pair NETDB_INTERNAL and errno.
        // See also herrnoToAiErrno().
@@ -1612,7 +1606,8 @@ static int res_queryN(const char* name, res_target* target, res_state res, int*

        LOG(DEBUG) << __func__ << ": (" << cl << ", " << type << ")";

        n = res_nmkquery(res, QUERY, name, cl, type, NULL, 0, NULL, buf, sizeof(buf));
        n = res_nmkquery(QUERY, name, cl, type, /*data=*/nullptr, /*datalen=*/0, buf, sizeof(buf),
                         res->netcontext_flags);
        if (n > 0 &&
            (res->netcontext_flags &
             (NET_CONTEXT_FLAG_USE_DNS_OVER_TLS | NET_CONTEXT_FLAG_USE_EDNS)) &&
+9 −14
Original line number Diff line number Diff line
@@ -74,6 +74,7 @@

#include "hostent.h"
#include "netd_resolv/resolv.h"
#include "res_init.h"
#include "resolv_cache.h"
#include "resolv_private.h"
#include "stats.pb.h"
@@ -116,7 +117,7 @@ static void pad_v4v6_hostent(struct hostent* hp, char** bpp, char* ep);
static int dns_gethtbyaddr(const unsigned char* uaddr, int len, int af,
                           const android_net_context* netcontext, getnamaddr* info,
                           NetworkDnsEventReported* event);
static int dns_gethtbyname(const char* name, int af, getnamaddr* info);
static int dns_gethtbyname(ResState* res, const char* name, int af, getnamaddr* info);

#define BOUNDED_INCR(x)      \
    do {                     \
@@ -393,9 +394,8 @@ int resolv_gethostbyname(const char* name, int af, hostent* hp, char* buf, size_
                         NetworkDnsEventReported* event) {
    getnamaddr info;

    res_state res = res_get_state();
    if (res == nullptr) return EAI_MEMORY;
    res_setnetcontext(res, netcontext, event);
    ResState res;
    res_init(&res, netcontext, event);

    size_t size;
    switch (af) {
@@ -450,7 +450,7 @@ int resolv_gethostbyname(const char* name, int af, hostent* hp, char* buf, size_
    info.buf = buf;
    info.buflen = buflen;
    if (_hf_gethtbyname2(name, af, &info)) {
        int error = dns_gethtbyname(name, af, &info);
        int error = dns_gethtbyname(&res, name, af, &info);
        if (error != 0) return error;
    }
    *result = hp;
@@ -652,7 +652,7 @@ static void pad_v4v6_hostent(struct hostent* hp, char** bpp, char* ep) {
                         });
}

static int dns_gethtbyname(const char* name, int addr_type, getnamaddr* info) {
static int dns_gethtbyname(ResState* res, const char* name, int addr_type, getnamaddr* info) {
    int n, type;
    info->hp->h_addrtype = addr_type;

@@ -670,9 +670,6 @@ static int dns_gethtbyname(const char* name, int addr_type, getnamaddr* info) {
    }
    auto buf = std::make_unique<querybuf>();

    res_state res = res_get_state();
    if (!res) return EAI_MEMORY;

    int he;
    n = res_nsearch(res, name, C_IN, type, buf->buf, (int)sizeof(buf->buf), &he);
    if (n < 0) {
@@ -734,12 +731,10 @@ static int dns_gethtbyaddr(const unsigned char* uaddr, int len, int af,

    auto buf = std::make_unique<querybuf>();

    res_state res = res_get_state();
    if (!res) return EAI_MEMORY;

    res_setnetcontext(res, netcontext, event);
    ResState res;
    res_init(&res, netcontext, event);
    int he;
    n = res_nquery(res, qbuf, C_IN, T_PTR, buf->buf, (int)sizeof(buf->buf), &he);
    n = res_nquery(&res, qbuf, C_IN, T_PTR, buf->buf, (int)sizeof(buf->buf), &he);
    if (n < 0) {
        LOG(DEBUG) << __func__ << ": res_nquery failed (" << n << ")";
        // Note that res_nquery() doesn't set the pair NETDB_INTERNAL and errno.
+1 −0
Original line number Diff line number Diff line
@@ -140,6 +140,7 @@ using android::base::StringAppendF;
 * *****************************************
 */
const int CONFIG_MAX_ENTRIES = 64 * 2 * 5;
constexpr int DNSEVENT_SUBSAMPLING_MAP_DEFAULT_KEY = -1;

static time_t _time_now(void) {
    struct timeval tv;
Loading