From fef3c6a015f33ca92efc94eb3cb0e55616860db4 Mon Sep 17 00:00:00 2001 From: Willem Toorop Date: Wed, 12 Dec 2012 14:40:21 +0000 Subject: [PATCH] Allow for leading zero's in the octets of IPv4 addresses. See errata of RFC6742 which refers to RFC990... --- str2host.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) 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; } -- 2.47.3