]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
fix multiple ipv6hints entries
authorTom Carpay <tom@nlnetlabs.nl>
Tue, 25 May 2021 09:43:46 +0000 (11:43 +0200)
committerTom Carpay <tom@nlnetlabs.nl>
Tue, 25 May 2021 09:43:46 +0000 (11:43 +0200)
sldns/str2wire.c
sldns/wire2str.c

index 05a623a2dfe6a2d974fd8d9595fdd457abd2eccd..dba21a093f39009e43906af18211454f5d5e2316 100644 (file)
@@ -1087,7 +1087,7 @@ static int
 sldns_str2wire_svcbparam_ipv6hint(const char* val, uint8_t* rd, size_t* rd_len)
 {
        int count;
-       char ip_str[INET_ADDRSTRLEN+1];
+       char ip_str[INET6_ADDRSTRLEN+1];
        char *next_ip_str;
        uint32_t *ip_wire_dst;
        size_t i;
@@ -1113,9 +1113,9 @@ sldns_str2wire_svcbparam_ipv6hint(const char* val, uint8_t* rd, size_t* rd_len)
 
        while (count) {
                if (!(next_ip_str = strchr(val, ','))) {
-                       if (inet_pton(AF_INET, val, rd + *rd_len) != 1)
-                               *rd_len += LDNS_IP6ADDRLEN;
+                       if (inet_pton(AF_INET6, val, rd + *rd_len) != 1)
                                break;
+                       *rd_len += LDNS_IP6ADDRLEN;
 
                        assert(count == 1);
 
@@ -1125,12 +1125,11 @@ sldns_str2wire_svcbparam_ipv6hint(const char* val, uint8_t* rd, size_t* rd_len)
                else {
                        memcpy(ip_str, val, next_ip_str - val);
                        ip_str[next_ip_str - val] = 0;
-                       if (inet_pton(AF_INET, ip_str, rd + *rd_len) != 1) {
-                               *rd_len += LDNS_IP6ADDRLEN;
-
+                       if (inet_pton(AF_INET6, ip_str, rd + *rd_len) != 1) {
                                val = ip_str; /* to use in error reporting below */
                                break;
                        }
+                       *rd_len += LDNS_IP6ADDRLEN;
 
                        val = next_ip_str + 1;
                }
index 0d41a2bb884846fb897a95f42d9ffd15686086bc..4c5065ee58e8c27d3e1d4dc024ca54241ad81090 100644 (file)
@@ -1015,14 +1015,14 @@ int sldns_wire2str_svcparam_ipv6hint2str(char** s,
                        return 0; /* wireformat error, incorrect size or inet family */
 
                w += sldns_str_print(s, slen, "=%s", ip_str);
-               data += LDNS_IP6ADDRLEN / sizeof(uint16_t);
+               data += LDNS_IP6ADDRLEN;
 
                while ((data_len -= LDNS_IP6ADDRLEN) > 0) {
                        if (inet_ntop(AF_INET6, data, ip_str, sizeof(ip_str)) == NULL)
                                return 0; /* wireformat error, incorrect size or inet family */
 
                        w += sldns_str_print(s, slen, ",%s", ip_str);
-                       data += LDNS_IP6ADDRLEN / sizeof(uint16_t);
+                       data += LDNS_IP6ADDRLEN;
                }
        }