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

Commit 1b43c810 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Exclude source port 5353 from DNS query" am: 8600c688

parents c585e605 8600c688
Loading
Loading
Loading
Loading
+4 −6
Original line number Original line Diff line number Diff line
@@ -253,7 +253,7 @@ static struct timespec evNowTime(void) {
// END: Code copied from ISC eventlib
// END: Code copied from ISC eventlib


/* BIONIC-BEGIN: implement source port randomization */
/* BIONIC-BEGIN: implement source port randomization */
static int random_bind(int s, int family, bool isMdns) {
static int random_bind(int s, int family) {
    sockaddr_union u;
    sockaddr_union u;
    int j;
    int j;
    socklen_t slen;
    socklen_t slen;
@@ -281,7 +281,7 @@ static int random_bind(int s, int family, bool isMdns) {
        int port = 1025 + (arc4random_uniform(65535 - 1025));
        int port = 1025 + (arc4random_uniform(65535 - 1025));
        // RFC 6762 section 5.1: Don't use 5353 source port on one-shot Multicast DNS queries. DNS
        // RFC 6762 section 5.1: Don't use 5353 source port on one-shot Multicast DNS queries. DNS
        // resolver does not fully compliant mDNS.
        // resolver does not fully compliant mDNS.
        if (isMdns && port == 5353) continue;
        if (port == 5353) continue;


        if (family == AF_INET)
        if (family == AF_INET)
            u.sin.sin_port = htons(port);
            u.sin.sin_port = htons(port);
@@ -779,7 +779,7 @@ same_ns:
            }
            }
        }
        }
        errno = 0;
        errno = 0;
        if (random_bind(statp->tcp_nssock, nsap->sa_family, false /* isMdns */) < 0) {
        if (random_bind(statp->tcp_nssock, nsap->sa_family) < 0) {
            *terrno = errno;
            *terrno = errno;
            dump_error("bind/vc", nsap);
            dump_error("bind/vc", nsap);
            statp->closeSockets();
            statp->closeSockets();
@@ -1082,9 +1082,7 @@ static int setupUdpSocket(ResState* statp, const sockaddr* sockap, unique_fd* fd
        }
        }
    }
    }


    const auto addr = IPSockAddr::toIPSockAddr(*sockap);
    if (random_bind(*fd_out, sockap->sa_family) < 0) {
    const bool isMdns = (addr == mdns_addrs[0] || addr == mdns_addrs[1]);
    if (random_bind(*fd_out, sockap->sa_family, isMdns) < 0) {
        *terrno = errno;
        *terrno = errno;
        dump_error("bind", sockap);
        dump_error("bind", sockap);
        return 0;
        return 0;