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

Commit 0771515e authored by Bernie Innocenti's avatar Bernie Innocenti
Browse files

Fix benign case of uninitialized variable

When the "resnsend" command is throttled by the query limiter, rcode
was uninitialized. The -Wconditional-uninitialized flag detects this,
but since resNSendToAiError() doesn't read rcode when nsendAns < 0,
there was no actual bug.

Change-Id: I5a7cb2ab5d627ace5b12377025b99c380fbf0beb
parent effead99
Loading
Loading
Loading
Loading
+6 −5
Original line number Diff line number Diff line
@@ -886,12 +886,13 @@ void DnsProxyListener::ResNSendHandler::run() {

    // Send DNS query
    std::vector<uint8_t> ansBuf(MAXPACKET, 0);
    int arcode, nsendAns = -1;
    int rcode = ns_r_noerror;
    int nsendAns = -1;
    NetworkDnsEventReported event;
    initDnsEvent(&event);
    if (queryLimiter.start(uid)) {
        nsendAns = resolv_res_nsend(&mNetContext, msg.data(), msgLen, ansBuf.data(), MAXPACKET,
                                    &arcode, static_cast<ResNsendFlags>(mFlags), &event);
                                    &rcode, static_cast<ResNsendFlags>(mFlags), &event);
        queryLimiter.finish(uid);
    } else {
        LOG(WARNING) << "ResNSendHandler::run: resnsend: from UID " << uid
@@ -909,13 +910,13 @@ void DnsProxyListener::ResNSendHandler::run() {
        sendBE32(mClient, nsendAns);
        if (rr_type == ns_t_a || rr_type == ns_t_aaaa) {
            reportDnsEvent(INetdEventListener::EVENT_RES_NSEND, mNetContext, latencyUs,
                           resNSendToAiError(nsendAns, arcode), event, rr_name);
                           resNSendToAiError(nsendAns, rcode), event, rr_name);
        }
        return;
    }

    // Send rcode
    if (!sendBE32(mClient, arcode)) {
    if (!sendBE32(mClient, rcode)) {
        PLOG(WARNING) << "ResNSendHandler::run: resnsend: failed to send rcode to uid " << uid;
        return;
    }
@@ -932,7 +933,7 @@ void DnsProxyListener::ResNSendHandler::run() {
        const int total_ip_addr_count =
                extractResNsendAnswers((uint8_t*) ansBuf.data(), nsendAns, rr_type, &ip_addrs);
        reportDnsEvent(INetdEventListener::EVENT_RES_NSEND, mNetContext, latencyUs,
                       resNSendToAiError(nsendAns, arcode), event, rr_name, ip_addrs,
                       resNSendToAiError(nsendAns, rcode), event, rr_name, ip_addrs,
                       total_ip_addr_count);
    }
}