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

Commit c131f84c authored by Bernie Innocenti's avatar Bernie Innocenti Committed by android-build-merger
Browse files

Merge "Explicitly allocate ResState on the call stack"

am: 7803769c

Change-Id: I5ca2d577b8a70dd59f52647318c583a5ebdc669a
parents 483fc576 7803769c
Loading
Loading
Loading
Loading
+0 −1
Original line number Original line Diff line number Diff line
@@ -50,7 +50,6 @@ cc_library {
        "res_mkquery.cpp",
        "res_mkquery.cpp",
        "res_query.cpp",
        "res_query.cpp",
        "res_send.cpp",
        "res_send.cpp",
        "res_state.cpp",
        "res_stats.cpp",
        "res_stats.cpp",
        "Dns64Configuration.cpp",
        "Dns64Configuration.cpp",
        "DnsProxyListener.cpp",
        "DnsProxyListener.cpp",
+1 −0
Original line number Original line Diff line number Diff line
[Builtin Hooks]
[Builtin Hooks]
clang_format = true
clang_format = true
commit_msg_test_field = false


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


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


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


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

    /* 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);


    int he;
    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.
        // 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.
        // Note that res_searchN() doesn't set the pair NETDB_INTERNAL and errno.
        // See also herrnoToAiErrno().
        // 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 << ")";
        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 &&
        if (n > 0 &&
            (res->netcontext_flags &
            (res->netcontext_flags &
             (NET_CONTEXT_FLAG_USE_DNS_OVER_TLS | NET_CONTEXT_FLAG_USE_EDNS)) &&
             (NET_CONTEXT_FLAG_USE_DNS_OVER_TLS | NET_CONTEXT_FLAG_USE_EDNS)) &&
+9 −14
Original line number Original line Diff line number Diff line
@@ -74,6 +74,7 @@


#include "hostent.h"
#include "hostent.h"
#include "netd_resolv/resolv.h"
#include "netd_resolv/resolv.h"
#include "res_init.h"
#include "resolv_cache.h"
#include "resolv_cache.h"
#include "resolv_private.h"
#include "resolv_private.h"
#include "stats.pb.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,
static int dns_gethtbyaddr(const unsigned char* uaddr, int len, int af,
                           const android_net_context* netcontext, getnamaddr* info,
                           const android_net_context* netcontext, getnamaddr* info,
                           NetworkDnsEventReported* event);
                           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)      \
#define BOUNDED_INCR(x)      \
    do {                     \
    do {                     \
@@ -393,9 +394,8 @@ int resolv_gethostbyname(const char* name, int af, hostent* hp, char* buf, size_
                         NetworkDnsEventReported* event) {
                         NetworkDnsEventReported* event) {
    getnamaddr info;
    getnamaddr info;


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


    size_t size;
    size_t size;
    switch (af) {
    switch (af) {
@@ -450,7 +450,7 @@ int resolv_gethostbyname(const char* name, int af, hostent* hp, char* buf, size_
    info.buf = buf;
    info.buf = buf;
    info.buflen = buflen;
    info.buflen = buflen;
    if (_hf_gethtbyname2(name, af, &info)) {
    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;
        if (error != 0) return error;
    }
    }
    *result = hp;
    *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;
    int n, type;
    info->hp->h_addrtype = addr_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>();
    auto buf = std::make_unique<querybuf>();


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

    int he;
    int he;
    n = res_nsearch(res, name, C_IN, type, buf->buf, (int)sizeof(buf->buf), &he);
    n = res_nsearch(res, name, C_IN, type, buf->buf, (int)sizeof(buf->buf), &he);
    if (n < 0) {
    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>();
    auto buf = std::make_unique<querybuf>();


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

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


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