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

Commit 739f9571 authored by Ken Chen's avatar Ken Chen Committed by android-build-merger
Browse files

Merge "Disable sensitive logs"

am: 8e311c068a

Change-Id: Ie43bdedf0b31105c9e3c45e41d7d4e0e1bb9d60e
parents 75629835 c5077892
Loading
Loading
Loading
Loading
+54 −62
Original line number Original line Diff line number Diff line
@@ -38,7 +38,6 @@
#include <android-base/stringprintf.h>
#include <android-base/stringprintf.h>
#include <android/multinetwork.h>  // ResNsendFlags
#include <android/multinetwork.h>  // ResNsendFlags
#include <cutils/misc.h>           // FIRST_APPLICATION_UID
#include <cutils/misc.h>           // FIRST_APPLICATION_UID
#include <log/log.h>
#include <netdutils/OperationLimiter.h>
#include <netdutils/OperationLimiter.h>
#include <netdutils/Slice.h>
#include <netdutils/Slice.h>
#include <private/android_filesystem_config.h>  // AID_SYSTEM
#include <private/android_filesystem_config.h>  // AID_SYSTEM
@@ -74,9 +73,9 @@ constexpr int MAXPACKET = 8 * 1024;
android::netdutils::OperationLimiter<uid_t> queryLimiter(MAX_QUERIES_PER_UID);
android::netdutils::OperationLimiter<uid_t> queryLimiter(MAX_QUERIES_PER_UID);


void logArguments(int argc, char** argv) {
void logArguments(int argc, char** argv) {
    if (!WOULD_LOG(DEBUG)) return;
    if (!WOULD_LOG(VERBOSE)) return;
    for (int i = 0; i < argc; i++) {
    for (int i = 0; i < argc; i++) {
        ALOGD("argv[%i]=%s", i, argv[i]);
        LOG(VERBOSE) << __func__ << ": argv[" << i << "]=" << (argv[i] ? argv[i] : "null");
    }
    }
}
}


@@ -300,7 +299,8 @@ void reportDnsEvent(int eventType, const android_net_context& netContext, int la


    const std::shared_ptr<INetdEventListener> listener = ResolverEventReporter::getListener();
    const std::shared_ptr<INetdEventListener> listener = ResolverEventReporter::getListener();
    if (!listener) {
    if (!listener) {
        ALOGE("DNS event not sent since NetdEventListenerService is unavailable.");
        LOG(ERROR) << __func__
                   << ": DNS event not sent since NetdEventListenerService is unavailable.";
        return;
        return;
    }
    }
    const int latencyMs = latencyUs / 1000;
    const int latencyMs = latencyUs / 1000;
@@ -360,14 +360,13 @@ void logDnsQueryResult(const struct hostent* hp) {
    if (!WOULD_LOG(DEBUG)) return;
    if (!WOULD_LOG(DEBUG)) return;
    if (hp == nullptr) return;
    if (hp == nullptr) return;


    ALOGD("DNS records:");
    LOG(DEBUG) << __func__ << ": DNS records:";
    for (int i = 0; hp->h_addr_list[i] != nullptr; i++) {
    for (int i = 0; hp->h_addr_list[i] != nullptr; i++) {
        char ip_addr[INET6_ADDRSTRLEN];
        char ip_addr[INET6_ADDRSTRLEN];
        if (inet_ntop(hp->h_addrtype, hp->h_addr_list[i], ip_addr, sizeof(ip_addr)) != nullptr) {
        if (inet_ntop(hp->h_addrtype, hp->h_addr_list[i], ip_addr, sizeof(ip_addr)) != nullptr) {
            ALOGD("[%d] %s, %d, %d, %s (%p)", i, hp->h_name ? hp->h_name : "null", hp->h_addrtype,
            LOG(DEBUG) << __func__ << ": [" << i << "] " << hp->h_addrtype;
                  hp->h_length, ip_addr, hp->h_addr_list[i]);
        } else {
        } else {
            ALOGD("[%d] numeric hostname translation fail (%d)", i, errno);
            PLOG(DEBUG) << __func__ << ": [" << i << "] numeric hostname translation fail";
        }
        }
    }
    }
}
}
@@ -378,29 +377,28 @@ void logDnsQueryResult(const addrinfo* res) {


    int i;
    int i;
    const addrinfo* ai;
    const addrinfo* ai;
    ALOGD("DNS records:");
    LOG(DEBUG) << __func__ << ": DNS records:";
    for (ai = res, i = 0; ai; ai = ai->ai_next, i++) {
    for (ai = res, i = 0; ai; ai = ai->ai_next, i++) {
        if ((ai->ai_family != AF_INET) && (ai->ai_family != AF_INET6)) continue;
        if ((ai->ai_family != AF_INET) && (ai->ai_family != AF_INET6)) continue;
        char ip_addr[INET6_ADDRSTRLEN];
        char ip_addr[INET6_ADDRSTRLEN];
        int ret = getnameinfo(ai->ai_addr, ai->ai_addrlen, ip_addr, sizeof(ip_addr), nullptr, 0,
        int ret = getnameinfo(ai->ai_addr, ai->ai_addrlen, ip_addr, sizeof(ip_addr), nullptr, 0,
                              NI_NUMERICHOST);
                              NI_NUMERICHOST);
        if (!ret) {
        if (!ret) {
            ALOGD("[%d] 0x%x,%d,%d,%d,%d,%s,%s,%p", i, ai->ai_flags, ai->ai_family, ai->ai_socktype,
            LOG(DEBUG) << __func__ << ": [" << i << "] " << ai->ai_flags << " " << ai->ai_family
                  ai->ai_protocol, ai->ai_addrlen, ai->ai_canonname ? ai->ai_canonname : "null",
                       << " " << ai->ai_socktype << " " << ai->ai_protocol;
                  ip_addr, ai);
        } else {
        } else {
            ALOGD("[%d] numeric hostname translation fail (%d)", i, ret);
            LOG(DEBUG) << __func__ << ": [" << i << "] numeric hostname translation fail " << ret;
        }
        }
    }
    }
}
}


bool isValidNat64Prefix(const netdutils::IPPrefix prefix) {
bool isValidNat64Prefix(const netdutils::IPPrefix prefix) {
    if (prefix.family() != AF_INET6) {
    if (prefix.family() != AF_INET6) {
        ALOGE("Only IPv6 NAT64 prefixes are supported (%u)", prefix.family());
        LOG(ERROR) << __func__ << ": Only IPv6 NAT64 prefixes are supported " << prefix.family();
        return false;
        return false;
    }
    }
    if (prefix.length() != 96) {
    if (prefix.length() != 96) {
        ALOGE("Only /96 NAT64 prefixes are supported (%d)", prefix.length());
        LOG(ERROR) << __func__ << ": Only /96 NAT64 prefixes are supported " << prefix.length();
        return false;
        return false;
    }
    }
    return true;
    return true;
@@ -427,11 +425,11 @@ bool synthesizeNat64PrefixWithARecord(const netdutils::IPPrefix& prefix, struct
        if (WOULD_LOG(DEBUG)) {
        if (WOULD_LOG(DEBUG)) {
            char buf[INET6_ADDRSTRLEN];  // big enough for either IPv4 or IPv6
            char buf[INET6_ADDRSTRLEN];  // big enough for either IPv4 or IPv6
            inet_ntop(AF_INET, &iaOriginal.s_addr, buf, sizeof(buf));
            inet_ntop(AF_INET, &iaOriginal.s_addr, buf, sizeof(buf));
            ALOGD("DNS A record: %s", buf);
            LOG(DEBUG) << __func__ << ": DNS A record: " << buf;
            inet_ntop(AF_INET6, &v6prefix->sin6_addr, buf, sizeof(buf));
            inet_ntop(AF_INET6, &v6prefix->sin6_addr, buf, sizeof(buf));
            ALOGD("NAT64 prefix: %s", buf);
            LOG(DEBUG) << __func__ << ": NAT64 prefix: " << buf;
            inet_ntop(AF_INET6, ia6, buf, sizeof(buf));
            inet_ntop(AF_INET6, ia6, buf, sizeof(buf));
            ALOGD("DNS64 Synthesized AAAA record: %s", buf);
            LOG(DEBUG) << __func__ << ": DNS64 Synthesized AAAA record: " << buf;
        }
        }
    }
    }
    hp->h_addrtype = AF_INET6;
    hp->h_addrtype = AF_INET6;
@@ -465,11 +463,11 @@ bool synthesizeNat64PrefixWithARecord(const netdutils::IPPrefix& prefix, addrinf
        if (WOULD_LOG(DEBUG)) {
        if (WOULD_LOG(DEBUG)) {
            char buf[INET6_ADDRSTRLEN];  // big enough for either IPv4 or IPv6
            char buf[INET6_ADDRSTRLEN];  // big enough for either IPv4 or IPv6
            inet_ntop(AF_INET, &sinOriginal.sin_addr.s_addr, buf, sizeof(buf));
            inet_ntop(AF_INET, &sinOriginal.sin_addr.s_addr, buf, sizeof(buf));
            ALOGD("DNS A record: %s", buf);
            LOG(DEBUG) << __func__ << ": DNS A record: " << buf;
            inet_ntop(AF_INET6, &v6prefix->sin6_addr, buf, sizeof(buf));
            inet_ntop(AF_INET6, &v6prefix->sin6_addr, buf, sizeof(buf));
            ALOGD("NAT64 prefix: %s", buf);
            LOG(DEBUG) << __func__ << ": NAT64 prefix: " << buf;
            inet_ntop(AF_INET6, &sin6->sin6_addr, buf, sizeof(buf));
            inet_ntop(AF_INET6, &sin6->sin6_addr, buf, sizeof(buf));
            ALOGD("DNS64 Synthesized AAAA record: %s", buf);
            LOG(DEBUG) << __func__ << ": DNS64 Synthesized AAAA record: " << buf;
        }
        }
    }
    }
    logDnsQueryResult(result);
    logDnsQueryResult(result);
@@ -612,7 +610,7 @@ void DnsProxyListener::GetAddrInfoHandler::doDns64Synthesis(int32_t* rv, addrinf
                return;
                return;
            }
            }
        } else {
        } else {
            ALOGE("getaddrinfo: from UID %d, max concurrent queries reached", uid);
            LOG(ERROR) << __func__ << ": from UID " << uid << ", max concurrent queries reached";
            return;
            return;
        }
        }
    }
    }
@@ -631,9 +629,9 @@ void DnsProxyListener::GetAddrInfoHandler::doDns64Synthesis(int32_t* rv, addrinf
}
}


void DnsProxyListener::GetAddrInfoHandler::run() {
void DnsProxyListener::GetAddrInfoHandler::run() {
    ALOGD("GetAddrInfoHandler, now for %s / %s / {%u,%u,%u,%u,%u,%u}", mHost, mService,
    LOG(DEBUG) << "GetAddrInfoHandler::run: {" << mNetContext.app_netid << " "
          mNetContext.app_netid, mNetContext.app_mark, mNetContext.dns_netid, mNetContext.dns_mark,
               << mNetContext.app_mark << " " << mNetContext.dns_netid << " "
          mNetContext.uid, mNetContext.flags);
               << mNetContext.dns_mark << " " << mNetContext.uid << " " << mNetContext.flags << "}";


    addrinfo* result = nullptr;
    addrinfo* result = nullptr;
    Stopwatch s;
    Stopwatch s;
@@ -647,7 +645,8 @@ void DnsProxyListener::GetAddrInfoHandler::run() {
        // Note that this error code is currently not passed down to the client.
        // Note that this error code is currently not passed down to the client.
        // android_getaddrinfo_proxy() returns EAI_NODATA on any error.
        // android_getaddrinfo_proxy() returns EAI_NODATA on any error.
        rv = EAI_MEMORY;
        rv = EAI_MEMORY;
        ALOGE("getaddrinfo: from UID %d, max concurrent queries reached", uid);
        LOG(ERROR) << "GetAddrInfoHandler::run: from UID " << uid
                   << ", max concurrent queries reached";
    }
    }


    doDns64Synthesis(&rv, &result);
    doDns64Synthesis(&rv, &result);
@@ -665,7 +664,7 @@ void DnsProxyListener::GetAddrInfoHandler::run() {
        }
        }
        success = success && sendBE32(mClient, 0);
        success = success && sendBE32(mClient, 0);
        if (!success) {
        if (!success) {
            ALOGW("Error writing DNS result to client");
            LOG(WARNING) << "GetAddrInfoHandler::run: Error writing DNS result to client";
        }
        }
    }
    }
    std::vector<std::string> ip_addrs;
    std::vector<std::string> ip_addrs;
@@ -702,7 +701,7 @@ int DnsProxyListener::GetAddrInfoCmd::runCommand(SocketClient *cli,
    if (argc != 8) {
    if (argc != 8) {
        char* msg = nullptr;
        char* msg = nullptr;
        asprintf( &msg, "Invalid number of arguments to getaddrinfo: %i", argc);
        asprintf( &msg, "Invalid number of arguments to getaddrinfo: %i", argc);
        ALOGW("%s", msg);
        LOG(WARNING) << "GetAddrInfoCmd::runCommand: " << (msg ? msg : "null");
        cli->sendMsg(ResponseCode::CommandParameterError, msg, false);
        cli->sendMsg(ResponseCode::CommandParameterError, msg, false);
        free(msg);
        free(msg);
        return -1;
        return -1;
@@ -747,10 +746,6 @@ int DnsProxyListener::GetAddrInfoCmd::runCommand(SocketClient *cli,
        hints->ai_protocol = ai_protocol;
        hints->ai_protocol = ai_protocol;
    }
    }


    ALOGD("GetAddrInfoHandler for %s / %s / {%u,%u,%u,%u,%u}", name ? name : "[nullhost]",
          service ? service : "[nullservice]", netcontext.app_netid, netcontext.app_mark,
          netcontext.dns_netid, netcontext.dns_mark, netcontext.uid);

    DnsProxyListener::GetAddrInfoHandler* handler =
    DnsProxyListener::GetAddrInfoHandler* handler =
            new DnsProxyListener::GetAddrInfoHandler(cli, name, service, hints, netcontext);
            new DnsProxyListener::GetAddrInfoHandler(cli, name, service, hints, netcontext);
    tryThreadOrError(cli, handler);
    tryThreadOrError(cli, handler);
@@ -767,21 +762,24 @@ int DnsProxyListener::ResNSendCommand::runCommand(SocketClient* cli, int argc, c


    const uid_t uid = cli->getUid();
    const uid_t uid = cli->getUid();
    if (argc != 4) {
    if (argc != 4) {
        ALOGW("resnsend: from UID %d, invalid number of arguments to resnsend: %d", uid, argc);
        LOG(WARNING) << "ResNSendCommand::runCommand: resnsend: from UID " << uid
                     << ", invalid number of arguments to resnsend: " << argc;
        sendBE32(cli, -EINVAL);
        sendBE32(cli, -EINVAL);
        return -1;
        return -1;
    }
    }


    unsigned netId;
    unsigned netId;
    if (!simpleStrtoul(argv[1], &netId)) {
    if (!simpleStrtoul(argv[1], &netId)) {
        ALOGW("resnsend: from UID %d, invalid netId", uid);
        LOG(WARNING) << "ResNSendCommand::runCommand: resnsend: from UID " << uid
                     << ", invalid netId";
        sendBE32(cli, -EINVAL);
        sendBE32(cli, -EINVAL);
        return -1;
        return -1;
    }
    }


    uint32_t flags;
    uint32_t flags;
    if (!simpleStrtoul(argv[2], &flags)) {
    if (!simpleStrtoul(argv[2], &flags)) {
        ALOGW("resnsend: from UID %d, invalid flags", uid);
        LOG(WARNING) << "ResNSendCommand::runCommand: resnsend: from UID " << uid
                     << ", invalid flags";
        sendBE32(cli, -EINVAL);
        sendBE32(cli, -EINVAL);
        return -1;
        return -1;
    }
    }
@@ -807,9 +805,9 @@ DnsProxyListener::ResNSendHandler::~ResNSendHandler() {
}
}


void DnsProxyListener::ResNSendHandler::run() {
void DnsProxyListener::ResNSendHandler::run() {
    ALOGD("ResNSendHandler, now for %s %u/ {%u,%u,%u,%u,%u,%u}", mMsg.c_str(), mFlags,
    LOG(DEBUG) << "ResNSendHandler::run: " << mFlags << " / {" << mNetContext.app_netid << " "
          mNetContext.app_netid, mNetContext.app_mark, mNetContext.dns_netid, mNetContext.dns_mark,
               << mNetContext.app_mark << " " << mNetContext.dns_netid << " "
          mNetContext.uid, mNetContext.flags);
               << mNetContext.dns_mark << " " << mNetContext.uid << " " << mNetContext.flags << "}";


    Stopwatch s;
    Stopwatch s;
    maybeFixupNetContext(&mNetContext);
    maybeFixupNetContext(&mNetContext);
@@ -834,7 +832,7 @@ void DnsProxyListener::ResNSendHandler::run() {
    if (!parseQuery(msg.data(), msgLen, &original_query_id, &rr_type, &rr_name) ||
    if (!parseQuery(msg.data(), msgLen, &original_query_id, &rr_type, &rr_name) ||
        !setQueryId(msg.data(), msgLen, arc4random_uniform(65536))) {
        !setQueryId(msg.data(), msgLen, arc4random_uniform(65536))) {
        // If the query couldn't be parsed, block the request.
        // If the query couldn't be parsed, block the request.
        ALOGW("resnsend: from UID %d, invalid query", uid);
        LOG(WARNING) << "ResNSendHandler::run: resnsend: from UID " << uid << ", invalid query";
        sendBE32(mClient, -EINVAL);
        sendBE32(mClient, -EINVAL);
        return;
        return;
    }
    }
@@ -847,7 +845,8 @@ void DnsProxyListener::ResNSendHandler::run() {
                                    &arcode, static_cast<ResNsendFlags>(mFlags));
                                    &arcode, static_cast<ResNsendFlags>(mFlags));
        queryLimiter.finish(uid);
        queryLimiter.finish(uid);
    } else {
    } else {
        ALOGW("resnsend: from UID %d, max concurrent queries reached", uid);
        LOG(WARNING) << "ResNSendHandler::run: resnsend: from UID " << uid
                     << ", max concurrent queries reached";
        nsendAns = -EBUSY;
        nsendAns = -EBUSY;
    }
    }


@@ -865,14 +864,14 @@ void DnsProxyListener::ResNSendHandler::run() {


    // Send rcode
    // Send rcode
    if (!sendBE32(mClient, arcode)) {
    if (!sendBE32(mClient, arcode)) {
        ALOGW("resnsend: failed to send rcode to uid %d: %s", uid, strerror(errno));
        PLOG(WARNING) << "ResNSendHandler::run: resnsend: failed to send rcode to uid " << uid;
        return;
        return;
    }
    }


    // Restore query id and send answer
    // Restore query id and send answer
    if (!setQueryId(ansBuf.data(), nsendAns, original_query_id) ||
    if (!setQueryId(ansBuf.data(), nsendAns, original_query_id) ||
        !sendLenAndData(mClient, nsendAns, ansBuf.data())) {
        !sendLenAndData(mClient, nsendAns, ansBuf.data())) {
        ALOGW("resnsend: failed to send answer to uid %d: %s", uid, strerror(errno));
        PLOG(WARNING) << "ResNSendHandler::run: resnsend: failed to send answer to uid " << uid;
        return;
        return;
    }
    }


@@ -897,7 +896,7 @@ int DnsProxyListener::GetHostByNameCmd::runCommand(SocketClient *cli,
    if (argc != 4) {
    if (argc != 4) {
        char* msg = nullptr;
        char* msg = nullptr;
        asprintf(&msg, "Invalid number of arguments to gethostbyname: %i", argc);
        asprintf(&msg, "Invalid number of arguments to gethostbyname: %i", argc);
        ALOGW("%s", msg);
        LOG(WARNING) << "GetHostByNameCmd::runCommand: " << (msg ? msg : "null");
        cli->sendMsg(ResponseCode::CommandParameterError, msg, false);
        cli->sendMsg(ResponseCode::CommandParameterError, msg, false);
        free(msg);
        free(msg);
        return -1;
        return -1;
@@ -960,7 +959,7 @@ void DnsProxyListener::GetHostByNameHandler::doDns64Synthesis(int32_t* rv, struc
            return;
            return;
        }
        }
    } else {
    } else {
        ALOGE("gethostbyname: from UID %d, max concurrent queries reached", uid);
        LOG(ERROR) << __func__ << ": from UID " << uid << ", max concurrent queries reached";
        return;
        return;
    }
    }


@@ -972,8 +971,6 @@ void DnsProxyListener::GetHostByNameHandler::doDns64Synthesis(int32_t* rv, struc
}
}


void DnsProxyListener::GetHostByNameHandler::run() {
void DnsProxyListener::GetHostByNameHandler::run() {
    ALOGD("DnsProxyListener::GetHostByNameHandler::run");

    Stopwatch s;
    Stopwatch s;
    maybeFixupNetContext(&mNetContext);
    maybeFixupNetContext(&mNetContext);
    const uid_t uid = mClient->getUid();
    const uid_t uid = mClient->getUid();
@@ -984,15 +981,13 @@ void DnsProxyListener::GetHostByNameHandler::run() {
        queryLimiter.finish(uid);
        queryLimiter.finish(uid);
    } else {
    } else {
        rv = EAI_MEMORY;
        rv = EAI_MEMORY;
        ALOGE("gethostbyname: from UID %d, max concurrent queries reached", uid);
        LOG(ERROR) << "GetHostByNameHandler::run: from UID " << uid
                   << ", max concurrent queries reached";
    }
    }


    doDns64Synthesis(&rv, &hp);
    doDns64Synthesis(&rv, &hp);
    const int latencyUs = lround(s.timeTakenUs());
    const int latencyUs = lround(s.timeTakenUs());

    LOG(DEBUG) << "GetHostByNameHandler::run: errno: " << (hp ? "success" : strerror(errno));
    ALOGD("GetHostByNameHandler::run gethostbyname errno: %s hp->h_name = %s, name_len = %zu",
          hp ? "success" : strerror(errno), (hp && hp->h_name) ? hp->h_name : "null",
          (hp && hp->h_name) ? strlen(hp->h_name) + 1 : 0);


    bool success = true;
    bool success = true;
    if (hp) {
    if (hp) {
@@ -1004,7 +999,7 @@ void DnsProxyListener::GetHostByNameHandler::run() {
    }
    }


    if (!success) {
    if (!success) {
        ALOGW("GetHostByNameHandler: Error writing DNS result to client");
        LOG(WARNING) << "GetHostByNameHandler::run: Error writing DNS result to client";
    }
    }


    std::vector<std::string> ip_addrs;
    std::vector<std::string> ip_addrs;
@@ -1027,7 +1022,7 @@ int DnsProxyListener::GetHostByAddrCmd::runCommand(SocketClient *cli,
    if (argc != 5) {
    if (argc != 5) {
        char* msg = nullptr;
        char* msg = nullptr;
        asprintf(&msg, "Invalid number of arguments to gethostbyaddr: %i", argc);
        asprintf(&msg, "Invalid number of arguments to gethostbyaddr: %i", argc);
        ALOGW("%s", msg);
        LOG(WARNING) << "GetHostByAddrCmd::runCommand: " << (msg ? msg : "null");
        cli->sendMsg(ResponseCode::CommandParameterError, msg, false);
        cli->sendMsg(ResponseCode::CommandParameterError, msg, false);
        free(msg);
        free(msg);
        return -1;
        return -1;
@@ -1046,7 +1041,7 @@ int DnsProxyListener::GetHostByAddrCmd::runCommand(SocketClient *cli,
    if (result <= 0) {
    if (result <= 0) {
        char* msg = nullptr;
        char* msg = nullptr;
        asprintf(&msg, "inet_pton(\"%s\") failed %s", addrStr, strerror(errno));
        asprintf(&msg, "inet_pton(\"%s\") failed %s", addrStr, strerror(errno));
        ALOGW("%s", msg);
        LOG(WARNING) << "GetHostByAddrCmd::runCommand: " << (msg ? msg : "null");
        cli->sendMsg(ResponseCode::OperationFailed, msg, false);
        cli->sendMsg(ResponseCode::OperationFailed, msg, false);
        free(addr);
        free(addr);
        free(msg);
        free(msg);
@@ -1119,13 +1114,11 @@ void DnsProxyListener::GetHostByAddrHandler::doDns64ReverseLookup(struct hostent
            (*hpp)->h_length = sizeof(struct in6_addr);
            (*hpp)->h_length = sizeof(struct in6_addr);
        }
        }
    } else {
    } else {
        ALOGE("gethostbyaddr: from UID %d, max concurrent queries reached", uid);
        LOG(ERROR) << __func__ << ": from UID " << uid << ", max concurrent queries reached";
    }
    }
}
}


void DnsProxyListener::GetHostByAddrHandler::run() {
void DnsProxyListener::GetHostByAddrHandler::run() {
    ALOGD("DnsProxyListener::GetHostByAddrHandler::run");

    Stopwatch s;
    Stopwatch s;
    maybeFixupNetContext(&mNetContext);
    maybeFixupNetContext(&mNetContext);
    const uid_t uid = mClient->getUid();
    const uid_t uid = mClient->getUid();
@@ -1137,15 +1130,14 @@ void DnsProxyListener::GetHostByAddrHandler::run() {
        queryLimiter.finish(uid);
        queryLimiter.finish(uid);
    } else {
    } else {
        rv = EAI_MEMORY;
        rv = EAI_MEMORY;
        ALOGE("gethostbyaddr: from UID %d, max concurrent queries reached", uid);
        LOG(ERROR) << "GetHostByAddrHandler::run: from UID " << uid
                   << ", max concurrent queries reached";
    }
    }


    doDns64ReverseLookup(&hp);
    doDns64ReverseLookup(&hp);
    const int latencyUs = int(s.timeTakenUs());
    const int latencyUs = int(s.timeTakenUs());


    ALOGD("GetHostByAddrHandler::run gethostbyaddr result: %s hp->h_name = %s, name_len = %zu",
    LOG(DEBUG) << "GetHostByAddrHandler::run: result: " << (hp ? "success" : gai_strerror(rv));
          hp ? "success" : gai_strerror(rv), (hp && hp->h_name) ? hp->h_name : "null",
          (hp && hp->h_name) ? strlen(hp->h_name) + 1 : 0);


    bool success = true;
    bool success = true;
    if (hp) {
    if (hp) {
@@ -1156,7 +1148,7 @@ void DnsProxyListener::GetHostByAddrHandler::run() {
    }
    }


    if (!success) {
    if (!success) {
        ALOGW("GetHostByAddrHandler: Error writing DNS result to client");
        LOG(WARNING) << "GetHostByAddrHandler::run: Error writing DNS result to client";
    }
    }


    reportDnsEvent(INetdEventListener::EVENT_GETHOSTBYADDR, mNetContext, latencyUs, rv,
    reportDnsEvent(INetdEventListener::EVENT_GETHOSTBYADDR, mNetContext, latencyUs, rv,
+4 −4
Original line number Original line Diff line number Diff line
@@ -27,7 +27,7 @@
bool resolv_init(const ResolverNetdCallbacks& callbacks) {
bool resolv_init(const ResolverNetdCallbacks& callbacks) {
    android::base::InitLogging(/*argv=*/nullptr);
    android::base::InitLogging(/*argv=*/nullptr);
    android::base::SetDefaultTag("libnetd_resolv");
    android::base::SetDefaultTag("libnetd_resolv");
    LOG(INFO) << "Initializing resolver";
    LOG(INFO) << __func__ << "Initializing resolver";
    const std::string logSeverityStr =
    const std::string logSeverityStr =
            android::base::GetProperty("persist.sys.nw_dns_resolver_log", "WARNING");
            android::base::GetProperty("persist.sys.nw_dns_resolver_log", "WARNING");
    android::base::SetMinimumLogSeverity(logSeverityStrToEnum(logSeverityStr));
    android::base::SetMinimumLogSeverity(logSeverityStrToEnum(logSeverityStr));
@@ -60,16 +60,16 @@ DnsResolver* DnsResolver::getInstance() {


bool DnsResolver::start() {
bool DnsResolver::start() {
    if (!verifyCallbacks()) {
    if (!verifyCallbacks()) {
        LOG(ERROR) << "Callback verification failed";
        LOG(ERROR) << __func__ << "Callback verification failed";
        return false;
        return false;
    }
    }
    if (mDnsProxyListener.startListener()) {
    if (mDnsProxyListener.startListener()) {
        PLOG(ERROR) << "Unable to start DnsProxyListener";
        PLOG(ERROR) << __func__ << "Unable to start DnsProxyListener";
        return false;
        return false;
    }
    }
    binder_status_t ret;
    binder_status_t ret;
    if ((ret = DnsResolverService::start()) != STATUS_OK) {
    if ((ret = DnsResolverService::start()) != STATUS_OK) {
        LOG(ERROR) << "Unable to start DnsResolverService: " << ret;
        LOG(ERROR) << __func__ << "Unable to start DnsResolverService: " << ret;
        return false;
        return false;
    }
    }
    return true;
    return true;
+11 −10
Original line number Original line Diff line number Diff line
@@ -361,7 +361,7 @@ int android_getaddrinfofornetcontext(const char* hostname, const char* servname,
            if (tmp.ai_socktype == ANY && ex.e_socktype != ANY) tmp.ai_socktype = ex.e_socktype;
            if (tmp.ai_socktype == ANY && ex.e_socktype != ANY) tmp.ai_socktype = ex.e_socktype;
            if (tmp.ai_protocol == ANY && ex.e_protocol != ANY) tmp.ai_protocol = ex.e_protocol;
            if (tmp.ai_protocol == ANY && ex.e_protocol != ANY) tmp.ai_protocol = ex.e_protocol;


            LOG(DEBUG) << "explore_numeric: ai_family=" << tmp.ai_family
            LOG(DEBUG) << __func__ << ": explore_numeric: ai_family=" << tmp.ai_family
                       << " ai_socktype=" << tmp.ai_socktype << " ai_protocol=" << tmp.ai_protocol;
                       << " ai_socktype=" << tmp.ai_socktype << " ai_protocol=" << tmp.ai_protocol;
            if (hostname == nullptr)
            if (hostname == nullptr)
                error = explore_null(&tmp, servname, &cur->ai_next);
                error = explore_null(&tmp, servname, &cur->ai_next);
@@ -409,7 +409,7 @@ int android_getaddrinfofornetcontext(const char* hostname, const char* servname,
            if (tmp.ai_socktype == ANY && ex.e_socktype != ANY) tmp.ai_socktype = ex.e_socktype;
            if (tmp.ai_socktype == ANY && ex.e_socktype != ANY) tmp.ai_socktype = ex.e_socktype;
            if (tmp.ai_protocol == ANY && ex.e_protocol != ANY) tmp.ai_protocol = ex.e_protocol;
            if (tmp.ai_protocol == ANY && ex.e_protocol != ANY) tmp.ai_protocol = ex.e_protocol;


            LOG(DEBUG) << "explore_fqdn(): ai_family=" << tmp.ai_family
            LOG(DEBUG) << __func__ << ": explore_fqdn(): ai_family=" << tmp.ai_family
                       << " ai_socktype=" << tmp.ai_socktype << " ai_protocol=" << tmp.ai_protocol;
                       << " ai_socktype=" << tmp.ai_socktype << " ai_protocol=" << tmp.ai_protocol;
            error = explore_fqdn(&tmp, hostname, servname, &cur->ai_next, netcontext);
            error = explore_fqdn(&tmp, hostname, servname, &cur->ai_next, netcontext);


@@ -478,6 +478,8 @@ static int explore_null(const struct addrinfo* pai, const char* servname, struct
    struct addrinfo sentinel;
    struct addrinfo sentinel;
    int error;
    int error;


    LOG(DEBUG) << __func__;

    assert(pai != NULL);
    assert(pai != NULL);
    /* servname may be NULL */
    /* servname may be NULL */
    assert(res != NULL);
    assert(res != NULL);
@@ -589,6 +591,8 @@ static int explore_numeric_scope(const struct addrinfo* pai, const char* hostnam
    const char *cp, *scope, *addr;
    const char *cp, *scope, *addr;
    struct sockaddr_in6* sin6;
    struct sockaddr_in6* sin6;


    LOG(DEBUG) << __func__;

    assert(pai != NULL);
    assert(pai != NULL);
    /* hostname may be NULL */
    /* hostname may be NULL */
    /* servname may be NULL */
    /* servname may be NULL */
@@ -936,9 +940,8 @@ static struct addrinfo* getanswer(const querybuf* answer, int anslen, const char
            }
            }
        } else if (type != qtype) {
        } else if (type != qtype) {
            if (type != T_KEY && type != T_SIG)
            if (type != T_KEY && type != T_SIG)
                LOG(DEBUG) << __func__ << "(getanswer): asked for \"" << qname << " "
                LOG(DEBUG) << __func__ << ": asked for \"" << qname << " " << p_class(C_IN) << " "
                           << p_class(C_IN) << " " << p_type(qtype) << "\", got type \""
                           << p_type(qtype) << "\", got type \"" << p_type(type) << "\"";
                           << p_type(type) << "\"";
            cp += n;
            cp += n;
            continue; /* XXX - had_error++ ? */
            continue; /* XXX - had_error++ ? */
        }
        }
@@ -946,8 +949,8 @@ static struct addrinfo* getanswer(const querybuf* answer, int anslen, const char
            case T_A:
            case T_A:
            case T_AAAA:
            case T_AAAA:
                if (strcasecmp(canonname, bp) != 0) {
                if (strcasecmp(canonname, bp) != 0) {
                    LOG(DEBUG) << __func__ << "(getanswer): asked for \"" << canonname
                    LOG(DEBUG) << __func__ << ": asked for \"" << canonname << "\", got \"" << bp
                               << "\", got \"" << bp << "\"";
                               << "\"";
                    cp += n;
                    cp += n;
                    continue; /* XXX - had_error++ ? */
                    continue; /* XXX - had_error++ ? */
                }
                }
@@ -1589,7 +1592,7 @@ static int res_queryN(const char* name, res_target* target, res_state res, int*
        answer = t->answer;
        answer = t->answer;
        anslen = t->anslen;
        anslen = t->anslen;


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


        n = res_nmkquery(res, QUERY, name, cl, type, NULL, 0, NULL, buf, sizeof(buf));
        n = res_nmkquery(res, QUERY, name, cl, type, NULL, 0, NULL, buf, sizeof(buf));
        if (n > 0 && (res->options & (RES_USE_EDNS0 | RES_USE_DNSSEC)) != 0 && !retried)
        if (n > 0 && (res->options & (RES_USE_EDNS0 | RES_USE_DNSSEC)) != 0 && !retried)
@@ -1790,8 +1793,6 @@ static int res_querydomainN(const char* name, const char* domain, res_target* ta


    assert(name != NULL);
    assert(name != NULL);


    LOG(DEBUG) << __func__ << "(\"" << name << "\", " << (domain ? domain : "<null>") << ")";

    if (domain == NULL) {
    if (domain == NULL) {
        // Check for trailing '.'; copy without '.' if present.
        // Check for trailing '.'; copy without '.' if present.
        n = strlen(name);
        n = strlen(name);
+10 −11
Original line number Original line Diff line number Diff line
@@ -277,17 +277,16 @@ static struct hostent* getanswer(const querybuf* answer, int anslen, const char*
        }
        }
        if (type != qtype) {
        if (type != qtype) {
            if (type != T_KEY && type != T_SIG)
            if (type != T_KEY && type != T_SIG)
                LOG(DEBUG) << __func__ << "(getanswer): asked for \"" << qname << " "
                LOG(DEBUG) << __func__ << ": asked for \"" << qname << " " << p_class(C_IN) << " "
                           << p_class(C_IN) << " " << p_type(qtype) << "\", got type \""
                           << p_type(qtype) << "\", got type \"" << p_type(type) << "\"";
                           << p_type(type) << "\"";
            cp += n;
            cp += n;
            continue; /* XXX - had_error++ ? */
            continue; /* XXX - had_error++ ? */
        }
        }
        switch (type) {
        switch (type) {
            case T_PTR:
            case T_PTR:
                if (strcasecmp(tname, bp) != 0) {
                if (strcasecmp(tname, bp) != 0) {
                    LOG(DEBUG) << __func__ << "(getanswer): asked for \"" << qname << "\", got \""
                    LOG(DEBUG) << __func__ << ": asked for \"" << qname << "\", got \"" << bp
                               << bp << "\"";
                               << "\"";
                    cp += n;
                    cp += n;
                    continue; /* XXX - had_error++ ? */
                    continue; /* XXX - had_error++ ? */
                }
                }
@@ -314,8 +313,8 @@ static struct hostent* getanswer(const querybuf* answer, int anslen, const char*
            case T_A:
            case T_A:
            case T_AAAA:
            case T_AAAA:
                if (strcasecmp(hent->h_name, bp) != 0) {
                if (strcasecmp(hent->h_name, bp) != 0) {
                    LOG(DEBUG) << __func__ << "(getanswer): asked for \"" << hent->h_name
                    LOG(DEBUG) << __func__ << ": asked for \"" << hent->h_name << "\", got \"" << bp
                               << "\", got \"" << bp << "\"";
                               << "\"";
                    cp += n;
                    cp += n;
                    continue; /* XXX - had_error++ ? */
                    continue; /* XXX - had_error++ ? */
                }
                }
@@ -342,13 +341,13 @@ static struct hostent* getanswer(const querybuf* answer, int anslen, const char*
                bp += sizeof(align) - (size_t)((u_long) bp % sizeof(align));
                bp += sizeof(align) - (size_t)((u_long) bp % sizeof(align));


                if (bp + n >= ep) {
                if (bp + n >= ep) {
                    LOG(DEBUG) << "size (" << n << ") too big";
                    LOG(DEBUG) << __func__ << ": size (" << n << ") too big";
                    had_error++;
                    had_error++;
                    continue;
                    continue;
                }
                }
                if (hap >= &addr_ptrs[MAXADDRS - 1]) {
                if (hap >= &addr_ptrs[MAXADDRS - 1]) {
                    if (!toobig++) {
                    if (!toobig++) {
                        LOG(DEBUG) << "Too many addresses (" << MAXADDRS << ")";
                        LOG(DEBUG) << __func__ << ": Too many addresses (" << MAXADDRS << ")";
                    }
                    }
                    cp += n;
                    cp += n;
                    continue;
                    continue;
@@ -784,7 +783,7 @@ static int dns_gethtbyname(const char* name, int addr_type, getnamaddr* info) {
    int herrno = NETDB_INTERNAL;
    int herrno = NETDB_INTERNAL;
    n = res_nsearch(res, name, C_IN, type, buf->buf, (int) sizeof(buf->buf), &herrno);
    n = res_nsearch(res, name, C_IN, type, buf->buf, (int) sizeof(buf->buf), &herrno);
    if (n < 0) {
    if (n < 0) {
        LOG(DEBUG) << "res_nsearch failed (" << n << ")";
        LOG(DEBUG) << __func__ << ": res_nsearch failed (" << n << ")";
        // Pass herrno to catch more detailed errors rather than EAI_NODATA.
        // Pass herrno to catch more detailed errors rather than EAI_NODATA.
        return herrnoToAiErrno(herrno);
        return herrnoToAiErrno(herrno);
    }
    }
@@ -842,7 +841,7 @@ static int dns_gethtbyaddr(const unsigned char* uaddr, int len, int af,
    int herrno = NETDB_INTERNAL;
    int herrno = NETDB_INTERNAL;
    n = res_nquery(res, qbuf, C_IN, T_PTR, buf->buf, (int) sizeof(buf->buf), &herrno);
    n = res_nquery(res, qbuf, C_IN, T_PTR, buf->buf, (int) sizeof(buf->buf), &herrno);
    if (n < 0) {
    if (n < 0) {
        LOG(DEBUG) << "res_nquery failed (" << n << ")";
        LOG(DEBUG) << __func__ << ": res_nquery failed (" << n << ")";
        return herrnoToAiErrno(herrno);
        return herrnoToAiErrno(herrno);
    }
    }
    hostent* hp =
    hostent* hp =
+33 −31

File changed.

Preview size limit exceeded, changes collapsed.

Loading