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

Commit af16700e authored by martinwu's avatar martinwu
Browse files

Remove accessing errno in setQueryId()

Clean up errno in setQueryId() and adjust the error messages/errno.

test: atest
bug: 238040801
Change-Id: I663b63da6b57d57cbd188826033beb048a3c6ab8
parent 078a976a
Loading
Loading
Loading
Loading
+9 −4
Original line number Diff line number Diff line
@@ -239,7 +239,7 @@ int resNSendToAiError(int err, int rcode) {

bool setQueryId(span<uint8_t> msg, uint16_t query_id) {
    if ((size_t)msg.size() < sizeof(HEADER)) {
        errno = EINVAL;
        LOG(ERROR) << __func__ << ": Invalid parameter";
        return false;
    }
    auto hp = reinterpret_cast<HEADER*>(msg.data());
@@ -1085,9 +1085,14 @@ void DnsProxyListener::ResNSendHandler::run() {
        return;
    }

    // Restore query id and send answer
    if (!setQueryId({ansBuf.data(), ansLen}, original_query_id) ||
        !sendLenAndData(mClient, ansLen, ansBuf.data())) {
    // Restore query id
    if (!setQueryId({ansBuf.data(), ansLen}, original_query_id)) {
        LOG(WARNING) << "ResNSendHandler::run: resnsend: failed to restore query id";
        return;
    }

    // Send answer
    if (!sendLenAndData(mClient, ansLen, ansBuf.data())) {
        PLOG(WARNING) << "ResNSendHandler::run: resnsend: failed to send answer to uid " << uid
                      << " pid " << mClient->getPid();
        return;
+0 −1
Original line number Diff line number Diff line
@@ -1792,7 +1792,6 @@ static int res_searchN(const char* name, res_target* target, ResState* res, int*

    hp = (HEADER*)(void*)target->answer.data();

    errno = 0;
    *herrno = HOST_NOT_FOUND; /* default, if we never query */
    dots = 0;
    for (cp = name; *cp; cp++) dots += (*cp == '.');
+0 −1
Original line number Diff line number Diff line
@@ -211,7 +211,6 @@ int res_nsearch(ResState* statp, const char* name, /* domain name */
    int got_nodata = 0, got_servfail = 0, root_on_list = 0;
    int tried_as_is = 0;

    errno = 0;
    *herrno = HOST_NOT_FOUND; /* True if we never query. */

    dots = 0;
+0 −1
Original line number Diff line number Diff line
@@ -780,7 +780,6 @@ same_ns:
                return -1;
            }
        }
        errno = 0;
        if (random_bind(statp->tcp_nssock, nsap->sa_family) < 0) {
            *terrno = errno;
            dump_error("bind/vc", nsap);