Skip to content

Commit

Permalink
bugfix #1260: Anticipate strchr can return NULL
Browse files Browse the repository at this point in the history
Thanks Stephan Zeisberg
  • Loading branch information
wtoorop committed May 2, 2017
1 parent eeba93b commit a675fe1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Changelog
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 6 additions & 4 deletions str2host.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit a675fe1

Please sign in to comment.