From: Willem Toorop Date: Tue, 2 May 2017 14:54:50 +0000 (+0200) Subject: bugfix #1260: Anticipate strchr can return NULL X-Git-Tag: release-1.7.1-rc1~71 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a675fe1f18f90fbb1489363d52dce11b1d541eba;p=thirdparty%2Fldns.git bugfix #1260: Anticipate strchr can return NULL Thanks Stephan Zeisberg --- diff --git a/Changelog b/Changelog index d7aa7116..16fbb9f5 100644 --- a/Changelog +++ b/Changelog @@ -1,4 +1,6 @@ 1.7.1 ????-??-?? + * bugfix #1260: Anticipate strchr returning NULL on unfound char + Thanks Stephan Zeisberg * bugfix #1257: Free after reallocing to 0 size Thanks Stephan Zeisberg * bugfix #1256: Check parse limit before t increment diff --git a/str2host.c b/str2host.c index f2a317be..968429cd 100644 --- a/str2host.c +++ b/str2host.c @@ -1548,11 +1548,11 @@ ldns_str2rdf_long_str(ldns_rdf **rd, const char *str) ldns_status ldns_str2rdf_hip(ldns_rdf **rd, const char *str) { - const char *hit = strchr(str, ' ') + 1; - const char *pk = hit == NULL ? NULL : strchr(hit, ' ') + 1; + const char *hit = str == NULL ? NULL : strchr(str, ' '); + const char *pk = hit == NULL ? NULL : strchr(hit + 1, ' '); size_t hit_size = hit == NULL ? 0 - : pk == NULL ? strlen(hit) : (size_t) (pk - hit) - 1; - size_t pk_size = pk == NULL ? 0 : strlen(pk); + : pk == NULL ? strlen(hit + 1) : (size_t) (pk - hit) - 1; + size_t pk_size = pk == NULL ? 0 : strlen(pk + 1); size_t hit_wire_size = (hit_size + 1) / 2; size_t pk_wire_size = ldns_b64_pton_calculate_size(pk_size); size_t rdf_size = 4 + hit_wire_size + pk_wire_size; @@ -1571,6 +1571,8 @@ ldns_str2rdf_hip(ldns_rdf **rd, const char *str) return LDNS_STATUS_SYNTAX_ERR; } + hit += 1; + pk += 1; if ((data = LDNS_XMALLOC(uint8_t, rdf_size)) == NULL) { return LDNS_STATUS_MEM_ERR;