X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fresolve%2Fresolved-dns-domain.c;h=eea73f6d5476851a1cfa8448e2782ccc7f9f0728;hp=94ffc0fac4abb37df7084cbd927634d082891db6;hb=6073b6f26ab9fc6bf335faa7073ec443eef093fd;hpb=74b2466e14a1961bf3ac0e8a60cfaceec705bd59 diff --git a/src/resolve/resolved-dns-domain.c b/src/resolve/resolved-dns-domain.c index 94ffc0fac..eea73f6d5 100644 --- a/src/resolve/resolved-dns-domain.c +++ b/src/resolve/resolved-dns-domain.c @@ -45,6 +45,9 @@ int dns_label_unescape(const char **name, char *dest, size_t sz) { if (sz <= 0) return -ENOSPC; + if (r >= DNS_LABEL_MAX) + return -EINVAL; + if (*n == '\\') { /* Escaped character */ @@ -114,6 +117,9 @@ int dns_label_escape(const char *p, size_t l, char **ret) { assert(p); assert(ret); + if (l > DNS_LABEL_MAX) + return -EINVAL; + s = malloc(l * 4 + 1); if (!s) return -ENOMEM; @@ -197,6 +203,9 @@ int dns_name_normalize(const char *s, char **_ret) { n += r; } + if (n > DNS_NAME_MAX) + return -EINVAL; + if (!GREEDY_REALLOC(ret, allocated, n + 1)) return -ENOMEM; @@ -209,7 +218,7 @@ int dns_name_normalize(const char *s, char **_ret) { unsigned long dns_name_hash_func(const void *s, const uint8_t hash_key[HASH_KEY_SIZE]) { const char *p = s; - unsigned long ul = 0; + unsigned long ul = hash_key[0]; int r; assert(p); @@ -224,7 +233,7 @@ unsigned long dns_name_hash_func(const void *s, const uint8_t hash_key[HASH_KEY_ label[r] = 0; ascii_strlower(label); - ul = hash_key[0] * ul + ul + string_hash_func(label, hash_key); + ul = ul * hash_key[1] + ul + string_hash_func(label, hash_key); } return ul; @@ -334,11 +343,15 @@ int dns_name_reverse(int family, const union in_addr_union *a, char **ret) { if (family == AF_INET) r = asprintf(ret, "%u.%u.%u.%u.in-addr.arpa", p[3], p[2], p[1], p[0]); else if (family == AF_INET6) - r = asprintf(ret, "%c.%c.%c.%c.%c.%c.%c.%c.%c.%c.%c.%c.%c.%c.%c.%c.ip6.arpa", - hexchar(p[15]), hexchar(p[14]), hexchar(p[13]), hexchar(p[12]), - hexchar(p[11]), hexchar(p[10]), hexchar(p[ 9]), hexchar(p[ 8]), - hexchar(p[ 7]), hexchar(p[ 6]), hexchar(p[ 5]), hexchar(p[ 4]), - hexchar(p[ 3]), hexchar(p[ 2]), hexchar(p[ 1]), hexchar(p[ 0])); + r = asprintf(ret, "%c.%c.%c.%c.%c.%c.%c.%c.%c.%c.%c.%c.%c.%c.%c.%c.%c.%c.%c.%c.%c.%c.%c.%c.%c.%c.%c.%c.%c.%c.%c.%c.ip6.arpa", + hexchar(p[15] & 0xF), hexchar(p[15] >> 4), hexchar(p[14] & 0xF), hexchar(p[14] >> 4), + hexchar(p[13] & 0xF), hexchar(p[13] >> 4), hexchar(p[12] & 0xF), hexchar(p[12] >> 4), + hexchar(p[11] & 0xF), hexchar(p[11] >> 4), hexchar(p[10] & 0xF), hexchar(p[10] >> 4), + hexchar(p[ 9] & 0xF), hexchar(p[ 9] >> 4), hexchar(p[ 8] & 0xF), hexchar(p[ 8] >> 4), + hexchar(p[ 7] & 0xF), hexchar(p[ 7] >> 4), hexchar(p[ 6] & 0xF), hexchar(p[ 6] >> 4), + hexchar(p[ 5] & 0xF), hexchar(p[ 5] >> 4), hexchar(p[ 4] & 0xF), hexchar(p[ 4] >> 4), + hexchar(p[ 3] & 0xF), hexchar(p[ 3] >> 4), hexchar(p[ 2] & 0xF), hexchar(p[ 2] >> 4), + hexchar(p[ 1] & 0xF), hexchar(p[ 1] >> 4), hexchar(p[ 0] & 0xF), hexchar(p[ 0] >> 4)); else return -EAFNOSUPPORT; if (r < 0)