]> git.ipfire.org Git - thirdparty/ldns.git/commitdiff
Allow for leading zero's in the octets of IPv4 addresses.
authorWillem Toorop <willem@NLnetLabs.nl>
Wed, 12 Dec 2012 14:40:21 +0000 (14:40 +0000)
committerWillem Toorop <willem@NLnetLabs.nl>
Wed, 12 Dec 2012 14:40:21 +0000 (14:40 +0000)
See errata of RFC6742 which refers to RFC990...

str2host.c

index a60030e3e34369fab01163323416512ec16731e3..1a5c0e5f61dad763ea58c5bbebdf13512fee4730 100644 (file)
@@ -387,12 +387,22 @@ ldns_status
 ldns_str2rdf_a(ldns_rdf **rd, const char *str)
 {
        in_addr_t address;
-        if (inet_pton(AF_INET, (char*)str, &address) != 1) {
-                return LDNS_STATUS_INVALID_IP4;
-        } else {
+       uint8_t a[4];
+       int l;
+
+        if (inet_pton(AF_INET, (char*)str, &address) == 1) {
                *rd = ldns_rdf_new_frm_data(
-                       LDNS_RDF_TYPE_A, sizeof(address), &address);
-        }
+                               LDNS_RDF_TYPE_A, sizeof(address), &address);
+        } else if (sscanf(str, "%3hhu.%3hhu.%3hhu.%3hhu%n",
+                               &a[0], &a[1], &a[2], &a[3], &l) == 4
+                       && l == (int)strlen(str) /* at end of data */
+                       && !strpbrk(str, "+-")   /* no signs anywhere */
+                       ) {
+               *rd = ldns_rdf_new_frm_data(
+                               LDNS_RDF_TYPE_A, sizeof(a), a);
+       } else {
+                return LDNS_STATUS_INVALID_IP4;
+       }
        return *rd?LDNS_STATUS_OK:LDNS_STATUS_MEM_ERR;
 }