Loading DnsProxyListener.cpp +1 −0 Original line number Original line Diff line number Diff line Loading @@ -24,6 +24,7 @@ #include <net/if.h> #include <net/if.h> #include <netdb.h> #include <netdb.h> #include <netinet/in.h> #include <netinet/in.h> #include <resolv.h> // b64_pton() #include <stdlib.h> #include <stdlib.h> #include <string.h> #include <string.h> #include <sys/socket.h> #include <sys/socket.h> Loading getaddrinfo.cpp +4 −1 Original line number Original line Diff line number Diff line Loading @@ -56,6 +56,8 @@ #include <android-base/logging.h> #include <android-base/logging.h> #include "netd_resolv/resolv.h" #include "netd_resolv/resolv.h" #include "res_comp.h" #include "res_debug.h" #include "res_init.h" #include "res_init.h" #include "resolv_cache.h" #include "resolv_cache.h" #include "resolv_private.h" #include "resolv_private.h" Loading Loading @@ -848,7 +850,6 @@ static struct addrinfo* getanswer(const std::vector<uint8_t>& answer, int anslen int type, ancount, qdcount; int type, ancount, qdcount; int haveanswer, had_error; int haveanswer, had_error; char tbuf[MAXDNAME]; char tbuf[MAXDNAME]; int (*name_ok)(const char*); char hostbuf[8 * 1024]; char hostbuf[8 * 1024]; assert(qname != NULL); assert(qname != NULL); Loading @@ -858,6 +859,8 @@ static struct addrinfo* getanswer(const std::vector<uint8_t>& answer, int anslen canonname = NULL; canonname = NULL; eom = answer.data() + anslen; eom = answer.data() + anslen; bool (*name_ok)(const char* dn); switch (qtype) { switch (qtype) { case T_A: case T_A: case T_AAAA: case T_AAAA: Loading gethnamaddr.cpp +9 −11 Original line number Original line Diff line number Diff line Loading @@ -74,9 +74,10 @@ #include "hostent.h" #include "hostent.h" #include "netd_resolv/resolv.h" #include "netd_resolv/resolv.h" #include "res_comp.h" #include "res_debug.h" // p_class(), p_type() #include "res_init.h" #include "res_init.h" #include "resolv_cache.h" #include "resolv_cache.h" #include "resolv_private.h" #include "stats.pb.h" #include "stats.pb.h" using android::net::NetworkDnsEventReported; using android::net::NetworkDnsEventReported; Loading @@ -91,10 +92,6 @@ using android::net::NetworkDnsEventReported; #define ALIGNBYTES (sizeof(uintptr_t) - 1) #define ALIGNBYTES (sizeof(uintptr_t) - 1) #define ALIGN(p) (((uintptr_t)(p) + ALIGNBYTES) & ~ALIGNBYTES) #define ALIGN(p) (((uintptr_t)(p) + ALIGNBYTES) & ~ALIGNBYTES) #define maybe_ok(res, nm, ok) ((ok)(nm) != 0) #define maybe_hnok(res, hn) maybe_ok((res), (hn), res_hnok) #define maybe_dnok(res, dn) maybe_ok((res), (dn), res_dnok) constexpr int MAXADDRS = 35; constexpr int MAXADDRS = 35; typedef union { typedef union { Loading Loading @@ -142,7 +139,6 @@ static struct hostent* getanswer(const querybuf* answer, int anslen, const char* char tbuf[MAXDNAME]; char tbuf[MAXDNAME]; char* addr_ptrs[MAXADDRS]; char* addr_ptrs[MAXADDRS]; const char* tname; const char* tname; int (*name_ok)(const char*); std::vector<char*> aliases; std::vector<char*> aliases; _DIAGASSERT(answer != NULL); _DIAGASSERT(answer != NULL); Loading @@ -151,6 +147,8 @@ static struct hostent* getanswer(const querybuf* answer, int anslen, const char* tname = qname; tname = qname; hent->h_name = NULL; hent->h_name = NULL; eom = answer->buf + anslen; eom = answer->buf + anslen; bool (*name_ok)(const char* dn); switch (qtype) { switch (qtype) { case T_A: case T_A: case T_AAAA: case T_AAAA: Loading @@ -177,7 +175,7 @@ static struct hostent* getanswer(const querybuf* answer, int anslen, const char* if (qdcount != 1) goto no_recovery; if (qdcount != 1) goto no_recovery; n = dn_expand(answer->buf, eom, cp, bp, (int) (ep - bp)); n = dn_expand(answer->buf, eom, cp, bp, (int) (ep - bp)); if ((n < 0) || !maybe_ok(res, bp, name_ok)) goto no_recovery; if ((n < 0) || !name_ok(bp)) goto no_recovery; BOUNDED_INCR(n + QFIXEDSZ); BOUNDED_INCR(n + QFIXEDSZ); if (qtype == T_A || qtype == T_AAAA) { if (qtype == T_A || qtype == T_AAAA) { Loading @@ -198,7 +196,7 @@ static struct hostent* getanswer(const querybuf* answer, int anslen, const char* had_error = 0; had_error = 0; while (ancount-- > 0 && cp < eom && !had_error) { while (ancount-- > 0 && cp < eom && !had_error) { n = dn_expand(answer->buf, eom, cp, bp, (int) (ep - bp)); n = dn_expand(answer->buf, eom, cp, bp, (int) (ep - bp)); if ((n < 0) || !maybe_ok(res, bp, name_ok)) { if ((n < 0) || !name_ok(bp)) { had_error++; had_error++; continue; continue; } } Loading @@ -219,7 +217,7 @@ static struct hostent* getanswer(const querybuf* answer, int anslen, const char* } } if ((qtype == T_A || qtype == T_AAAA) && type == T_CNAME) { if ((qtype == T_A || qtype == T_AAAA) && type == T_CNAME) { n = dn_expand(answer->buf, eom, cp, tbuf, (int) sizeof tbuf); n = dn_expand(answer->buf, eom, cp, tbuf, (int) sizeof tbuf); if ((n < 0) || !maybe_ok(res, tbuf, name_ok)) { if ((n < 0) || !name_ok(tbuf)) { had_error++; had_error++; continue; continue; } } Loading @@ -246,7 +244,7 @@ static struct hostent* getanswer(const querybuf* answer, int anslen, const char* } } if (qtype == T_PTR && type == T_CNAME) { if (qtype == T_PTR && type == T_CNAME) { n = dn_expand(answer->buf, eom, cp, tbuf, (int) sizeof tbuf); n = dn_expand(answer->buf, eom, cp, tbuf, (int) sizeof tbuf); if (n < 0 || !maybe_dnok(res, tbuf)) { if (n < 0 || !res_dnok(tbuf)) { had_error++; had_error++; continue; continue; } } Loading Loading @@ -279,7 +277,7 @@ static struct hostent* getanswer(const querybuf* answer, int anslen, const char* continue; /* XXX - had_error++ ? */ continue; /* XXX - had_error++ ? */ } } n = dn_expand(answer->buf, eom, cp, bp, (int) (ep - bp)); n = dn_expand(answer->buf, eom, cp, bp, (int) (ep - bp)); if ((n < 0) || !maybe_hnok(res, bp)) { if ((n < 0) || !res_hnok(bp)) { had_error++; had_error++; break; break; } } Loading res_cache.cpp +1 −0 Original line number Original line Diff line number Diff line Loading @@ -59,6 +59,7 @@ #include <server_configurable_flags/get_flags.h> #include <server_configurable_flags/get_flags.h> #include "DnsStats.h" #include "DnsStats.h" #include "res_comp.h" #include "res_debug.h" #include "res_debug.h" #include "resolv_private.h" #include "resolv_private.h" #include "util.h" #include "util.h" Loading res_comp.cpp +11 −47 Original line number Original line Diff line number Diff line Loading @@ -70,14 +70,13 @@ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ */ #include "res_comp.h" #include <arpa/nameser.h> #include <arpa/nameser.h> #include <ctype.h> #include <netinet/in.h> #include <netinet/in.h> #include <string.h> #include <string.h> #include <unistd.h> #include <unistd.h> #include "resolv_private.h" /* /* * Expand compressed domain name 'src' to full domain name. * Expand compressed domain name 'src' to full domain name. * 'msg' is a pointer to the begining of the message, * 'msg' is a pointer to the begining of the message, Loading @@ -89,7 +88,7 @@ int dn_expand(const uint8_t* msg, const uint8_t* eom, const uint8_t* src, char* int n = ns_name_uncompress(msg, eom, src, dst, (size_t) dstsiz); int n = ns_name_uncompress(msg, eom, src, dst, (size_t) dstsiz); if (n > 0 && dst[0] == '.') dst[0] = '\0'; if (n > 0 && dst[0] == '.') dst[0] = '\0'; return (n); return n; } } /* /* Loading Loading @@ -141,7 +140,7 @@ int dn_skipname(const uint8_t* ptr, const uint8_t* eom) { #define middlechar(c) (borderchar(c) || hyphenchar(c) || underscorechar(c)) #define middlechar(c) (borderchar(c) || hyphenchar(c) || underscorechar(c)) #define domainchar(c) ((c) > 0x20 && (c) < 0x7f) #define domainchar(c) ((c) > 0x20 && (c) < 0x7f) int res_hnok(const char* dn) { bool res_hnok(const char* dn) { int pch = PERIOD, ch = *dn++; int pch = PERIOD, ch = *dn++; while (ch != '\0') { while (ch != '\0') { Loading @@ -150,60 +149,25 @@ int res_hnok(const char* dn) { if (periodchar(ch)) { if (periodchar(ch)) { ; ; } else if (periodchar(pch)) { } else if (periodchar(pch)) { if (!borderchar(ch)) return (0); if (!borderchar(ch)) return false; } else if (periodchar(nch) || nch == '\0') { } else if (periodchar(nch) || nch == '\0') { if (!borderchar(ch)) return (0); if (!borderchar(ch)) return false; } else { } else { if (!middlechar(ch)) return (0); if (!middlechar(ch)) return false; } } pch = ch, ch = nch; pch = ch, ch = nch; } } return (1); return true; } /* * hostname-like (A, MX, WKS) owners can have "*" as their first label * but must otherwise be as a host name. */ int res_ownok(const char* dn) { if (asterchar(dn[0])) { if (periodchar(dn[1])) return (res_hnok(dn + 2)); if (dn[1] == '\0') return (1); } return (res_hnok(dn)); } /* * SOA RNAMEs and RP RNAMEs can have any printable character in their first * label, but the rest of the name has to look like a host name. */ int res_mailok(const char* dn) { int ch, escaped = 0; /* "." is a valid missing representation */ if (*dn == '\0') return (1); /* otherwise <label>.<hostname> */ while ((ch = *dn++) != '\0') { if (!domainchar(ch)) return (0); if (!escaped && periodchar(ch)) break; if (escaped) escaped = 0; else if (bslashchar(ch)) escaped = 1; } if (periodchar(ch)) return (res_hnok(dn)); return (0); } } /* /* * This function is quite liberal, since RFC 1034's character sets are only * This function is quite liberal, since RFC 1034's character sets are only * recommendations. * recommendations. */ */ int res_dnok(const char* dn) { bool res_dnok(const char* dn) { int ch; int ch; while ((ch = *dn++) != '\0') while ((ch = *dn++) != '\0') if (!domainchar(ch)) return (0); if (!domainchar(ch)) return false; return (1); return true; } } Loading
DnsProxyListener.cpp +1 −0 Original line number Original line Diff line number Diff line Loading @@ -24,6 +24,7 @@ #include <net/if.h> #include <net/if.h> #include <netdb.h> #include <netdb.h> #include <netinet/in.h> #include <netinet/in.h> #include <resolv.h> // b64_pton() #include <stdlib.h> #include <stdlib.h> #include <string.h> #include <string.h> #include <sys/socket.h> #include <sys/socket.h> Loading
getaddrinfo.cpp +4 −1 Original line number Original line Diff line number Diff line Loading @@ -56,6 +56,8 @@ #include <android-base/logging.h> #include <android-base/logging.h> #include "netd_resolv/resolv.h" #include "netd_resolv/resolv.h" #include "res_comp.h" #include "res_debug.h" #include "res_init.h" #include "res_init.h" #include "resolv_cache.h" #include "resolv_cache.h" #include "resolv_private.h" #include "resolv_private.h" Loading Loading @@ -848,7 +850,6 @@ static struct addrinfo* getanswer(const std::vector<uint8_t>& answer, int anslen int type, ancount, qdcount; int type, ancount, qdcount; int haveanswer, had_error; int haveanswer, had_error; char tbuf[MAXDNAME]; char tbuf[MAXDNAME]; int (*name_ok)(const char*); char hostbuf[8 * 1024]; char hostbuf[8 * 1024]; assert(qname != NULL); assert(qname != NULL); Loading @@ -858,6 +859,8 @@ static struct addrinfo* getanswer(const std::vector<uint8_t>& answer, int anslen canonname = NULL; canonname = NULL; eom = answer.data() + anslen; eom = answer.data() + anslen; bool (*name_ok)(const char* dn); switch (qtype) { switch (qtype) { case T_A: case T_A: case T_AAAA: case T_AAAA: Loading
gethnamaddr.cpp +9 −11 Original line number Original line Diff line number Diff line Loading @@ -74,9 +74,10 @@ #include "hostent.h" #include "hostent.h" #include "netd_resolv/resolv.h" #include "netd_resolv/resolv.h" #include "res_comp.h" #include "res_debug.h" // p_class(), p_type() #include "res_init.h" #include "res_init.h" #include "resolv_cache.h" #include "resolv_cache.h" #include "resolv_private.h" #include "stats.pb.h" #include "stats.pb.h" using android::net::NetworkDnsEventReported; using android::net::NetworkDnsEventReported; Loading @@ -91,10 +92,6 @@ using android::net::NetworkDnsEventReported; #define ALIGNBYTES (sizeof(uintptr_t) - 1) #define ALIGNBYTES (sizeof(uintptr_t) - 1) #define ALIGN(p) (((uintptr_t)(p) + ALIGNBYTES) & ~ALIGNBYTES) #define ALIGN(p) (((uintptr_t)(p) + ALIGNBYTES) & ~ALIGNBYTES) #define maybe_ok(res, nm, ok) ((ok)(nm) != 0) #define maybe_hnok(res, hn) maybe_ok((res), (hn), res_hnok) #define maybe_dnok(res, dn) maybe_ok((res), (dn), res_dnok) constexpr int MAXADDRS = 35; constexpr int MAXADDRS = 35; typedef union { typedef union { Loading Loading @@ -142,7 +139,6 @@ static struct hostent* getanswer(const querybuf* answer, int anslen, const char* char tbuf[MAXDNAME]; char tbuf[MAXDNAME]; char* addr_ptrs[MAXADDRS]; char* addr_ptrs[MAXADDRS]; const char* tname; const char* tname; int (*name_ok)(const char*); std::vector<char*> aliases; std::vector<char*> aliases; _DIAGASSERT(answer != NULL); _DIAGASSERT(answer != NULL); Loading @@ -151,6 +147,8 @@ static struct hostent* getanswer(const querybuf* answer, int anslen, const char* tname = qname; tname = qname; hent->h_name = NULL; hent->h_name = NULL; eom = answer->buf + anslen; eom = answer->buf + anslen; bool (*name_ok)(const char* dn); switch (qtype) { switch (qtype) { case T_A: case T_A: case T_AAAA: case T_AAAA: Loading @@ -177,7 +175,7 @@ static struct hostent* getanswer(const querybuf* answer, int anslen, const char* if (qdcount != 1) goto no_recovery; if (qdcount != 1) goto no_recovery; n = dn_expand(answer->buf, eom, cp, bp, (int) (ep - bp)); n = dn_expand(answer->buf, eom, cp, bp, (int) (ep - bp)); if ((n < 0) || !maybe_ok(res, bp, name_ok)) goto no_recovery; if ((n < 0) || !name_ok(bp)) goto no_recovery; BOUNDED_INCR(n + QFIXEDSZ); BOUNDED_INCR(n + QFIXEDSZ); if (qtype == T_A || qtype == T_AAAA) { if (qtype == T_A || qtype == T_AAAA) { Loading @@ -198,7 +196,7 @@ static struct hostent* getanswer(const querybuf* answer, int anslen, const char* had_error = 0; had_error = 0; while (ancount-- > 0 && cp < eom && !had_error) { while (ancount-- > 0 && cp < eom && !had_error) { n = dn_expand(answer->buf, eom, cp, bp, (int) (ep - bp)); n = dn_expand(answer->buf, eom, cp, bp, (int) (ep - bp)); if ((n < 0) || !maybe_ok(res, bp, name_ok)) { if ((n < 0) || !name_ok(bp)) { had_error++; had_error++; continue; continue; } } Loading @@ -219,7 +217,7 @@ static struct hostent* getanswer(const querybuf* answer, int anslen, const char* } } if ((qtype == T_A || qtype == T_AAAA) && type == T_CNAME) { if ((qtype == T_A || qtype == T_AAAA) && type == T_CNAME) { n = dn_expand(answer->buf, eom, cp, tbuf, (int) sizeof tbuf); n = dn_expand(answer->buf, eom, cp, tbuf, (int) sizeof tbuf); if ((n < 0) || !maybe_ok(res, tbuf, name_ok)) { if ((n < 0) || !name_ok(tbuf)) { had_error++; had_error++; continue; continue; } } Loading @@ -246,7 +244,7 @@ static struct hostent* getanswer(const querybuf* answer, int anslen, const char* } } if (qtype == T_PTR && type == T_CNAME) { if (qtype == T_PTR && type == T_CNAME) { n = dn_expand(answer->buf, eom, cp, tbuf, (int) sizeof tbuf); n = dn_expand(answer->buf, eom, cp, tbuf, (int) sizeof tbuf); if (n < 0 || !maybe_dnok(res, tbuf)) { if (n < 0 || !res_dnok(tbuf)) { had_error++; had_error++; continue; continue; } } Loading Loading @@ -279,7 +277,7 @@ static struct hostent* getanswer(const querybuf* answer, int anslen, const char* continue; /* XXX - had_error++ ? */ continue; /* XXX - had_error++ ? */ } } n = dn_expand(answer->buf, eom, cp, bp, (int) (ep - bp)); n = dn_expand(answer->buf, eom, cp, bp, (int) (ep - bp)); if ((n < 0) || !maybe_hnok(res, bp)) { if ((n < 0) || !res_hnok(bp)) { had_error++; had_error++; break; break; } } Loading
res_cache.cpp +1 −0 Original line number Original line Diff line number Diff line Loading @@ -59,6 +59,7 @@ #include <server_configurable_flags/get_flags.h> #include <server_configurable_flags/get_flags.h> #include "DnsStats.h" #include "DnsStats.h" #include "res_comp.h" #include "res_debug.h" #include "res_debug.h" #include "resolv_private.h" #include "resolv_private.h" #include "util.h" #include "util.h" Loading
res_comp.cpp +11 −47 Original line number Original line Diff line number Diff line Loading @@ -70,14 +70,13 @@ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ */ #include "res_comp.h" #include <arpa/nameser.h> #include <arpa/nameser.h> #include <ctype.h> #include <netinet/in.h> #include <netinet/in.h> #include <string.h> #include <string.h> #include <unistd.h> #include <unistd.h> #include "resolv_private.h" /* /* * Expand compressed domain name 'src' to full domain name. * Expand compressed domain name 'src' to full domain name. * 'msg' is a pointer to the begining of the message, * 'msg' is a pointer to the begining of the message, Loading @@ -89,7 +88,7 @@ int dn_expand(const uint8_t* msg, const uint8_t* eom, const uint8_t* src, char* int n = ns_name_uncompress(msg, eom, src, dst, (size_t) dstsiz); int n = ns_name_uncompress(msg, eom, src, dst, (size_t) dstsiz); if (n > 0 && dst[0] == '.') dst[0] = '\0'; if (n > 0 && dst[0] == '.') dst[0] = '\0'; return (n); return n; } } /* /* Loading Loading @@ -141,7 +140,7 @@ int dn_skipname(const uint8_t* ptr, const uint8_t* eom) { #define middlechar(c) (borderchar(c) || hyphenchar(c) || underscorechar(c)) #define middlechar(c) (borderchar(c) || hyphenchar(c) || underscorechar(c)) #define domainchar(c) ((c) > 0x20 && (c) < 0x7f) #define domainchar(c) ((c) > 0x20 && (c) < 0x7f) int res_hnok(const char* dn) { bool res_hnok(const char* dn) { int pch = PERIOD, ch = *dn++; int pch = PERIOD, ch = *dn++; while (ch != '\0') { while (ch != '\0') { Loading @@ -150,60 +149,25 @@ int res_hnok(const char* dn) { if (periodchar(ch)) { if (periodchar(ch)) { ; ; } else if (periodchar(pch)) { } else if (periodchar(pch)) { if (!borderchar(ch)) return (0); if (!borderchar(ch)) return false; } else if (periodchar(nch) || nch == '\0') { } else if (periodchar(nch) || nch == '\0') { if (!borderchar(ch)) return (0); if (!borderchar(ch)) return false; } else { } else { if (!middlechar(ch)) return (0); if (!middlechar(ch)) return false; } } pch = ch, ch = nch; pch = ch, ch = nch; } } return (1); return true; } /* * hostname-like (A, MX, WKS) owners can have "*" as their first label * but must otherwise be as a host name. */ int res_ownok(const char* dn) { if (asterchar(dn[0])) { if (periodchar(dn[1])) return (res_hnok(dn + 2)); if (dn[1] == '\0') return (1); } return (res_hnok(dn)); } /* * SOA RNAMEs and RP RNAMEs can have any printable character in their first * label, but the rest of the name has to look like a host name. */ int res_mailok(const char* dn) { int ch, escaped = 0; /* "." is a valid missing representation */ if (*dn == '\0') return (1); /* otherwise <label>.<hostname> */ while ((ch = *dn++) != '\0') { if (!domainchar(ch)) return (0); if (!escaped && periodchar(ch)) break; if (escaped) escaped = 0; else if (bslashchar(ch)) escaped = 1; } if (periodchar(ch)) return (res_hnok(dn)); return (0); } } /* /* * This function is quite liberal, since RFC 1034's character sets are only * This function is quite liberal, since RFC 1034's character sets are only * recommendations. * recommendations. */ */ int res_dnok(const char* dn) { bool res_dnok(const char* dn) { int ch; int ch; while ((ch = *dn++) != '\0') while ((ch = *dn++) != '\0') if (!domainchar(ch)) return (0); if (!domainchar(ch)) return false; return (1); return true; } }