From: Willem Toorop Date: Wed, 12 Dec 2012 14:40:21 +0000 (+0000) Subject: Allow for leading zero's in the octets of IPv4 addresses. X-Git-Tag: release-1.6.17rc1~153 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fef3c6a015f33ca92efc94eb3cb0e55616860db4;p=thirdparty%2Fldns.git Allow for leading zero's in the octets of IPv4 addresses. See errata of RFC6742 which refers to RFC990... --- diff --git a/str2host.c b/str2host.c index a60030e3..1a5c0e5f 100644 --- a/str2host.c +++ b/str2host.c @@ -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; }