Skip to content

Commit

Permalink
- Free memory leak in config strlist append.
Browse files Browse the repository at this point in the history
- make sure nsec3 comparison salt is initialized.


git-svn-id: file:///svn/unbound/trunk@4900 be551aaa-1e26-0410-a405-d3ace91eadb9
  • Loading branch information
wcawijngaards committed Sep 13, 2018
1 parent 90f0530 commit 75b8b8c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
2 changes: 2 additions & 0 deletions doc/Changelog
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
- in testcode, free async ids, initialise array, and check for null
pointer during test of the test. And use exit for return to note
irregular program stop.
- Free memory leak in config strlist append.
- make sure nsec3 comparison salt is initialized.

11 September 2018: Wouter
- Fixed unused return value warnings in contrib/fastrpz.patch for
Expand Down
9 changes: 7 additions & 2 deletions util/config_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,7 @@ config_get_option(struct config_file* cfg, const char* opt,
{
char buf[1024], nopt[64];
size_t len = sizeof(buf);
if(!opt) return 0;
if(opt && opt[strlen(opt)-1] == ':' && strlen(opt)<sizeof(nopt)) {
memmove(nopt, opt, strlen(opt));
nopt[strlen(opt)-1] = 0;
Expand Down Expand Up @@ -1526,11 +1527,15 @@ int ub_c_wrap(void)
int cfg_strlist_append(struct config_strlist_head* list, char* item)
{
struct config_strlist *s;
if(!item || !list)
if(!item || !list) {
free(item);
return 0;
}
s = (struct config_strlist*)calloc(1, sizeof(struct config_strlist));
if(!s)
if(!s) {
free(item);
return 0;
}
s->str = item;
s->next = NULL;
if(list->last)
Expand Down
1 change: 1 addition & 0 deletions util/config_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,7 @@ char* config_collate_cat(struct config_strlist* list);
* @param list: list head. zeroed at start.
* @param item: new item. malloced by caller. if NULL the insertion fails.
* @return true on success.
* on fail the item is free()ed.
*/
int cfg_strlist_append(struct config_strlist_head* list, char* item);

Expand Down
12 changes: 8 additions & 4 deletions validator/val_nsec3.c
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,10 @@ nsec3_hash_cmp(const void* c1, const void* c2)
}
(void)nsec3_get_salt(h1->nsec3, h1->rr, &s1, &s1len);
(void)nsec3_get_salt(h2->nsec3, h2->rr, &s2, &s2len);
if(s1len == 0 && s2len == 0)
return 0;
if(!s1) return -1;
if(!s2) return 1;
if(s1len != s2len) {
if(s1len < s2len)
return -1;
Expand Down Expand Up @@ -736,7 +740,7 @@ find_matching_nsec3(struct module_env* env, struct nsec3_filter* flt,
size_t i_rs;
int i_rr;
struct ub_packed_rrset_key* s;
struct nsec3_cached_hash* hash;
struct nsec3_cached_hash* hash = NULL;
int r;

/* this loop skips other-zone and unknown NSEC3s, also non-NSEC3 RRs */
Expand All @@ -748,7 +752,7 @@ find_matching_nsec3(struct module_env* env, struct nsec3_filter* flt,
if(r == 0) {
log_err("nsec3: malloc failure");
break; /* alloc failure */
} else if(r < 0)
} else if(r != 1)
continue; /* malformed NSEC3 */
else if(nsec3_hash_matches_owner(flt, hash, s)) {
*rrset = s; /* rrset with this name */
Expand Down Expand Up @@ -829,7 +833,7 @@ find_covering_nsec3(struct module_env* env, struct nsec3_filter* flt,
size_t i_rs;
int i_rr;
struct ub_packed_rrset_key* s;
struct nsec3_cached_hash* hash;
struct nsec3_cached_hash* hash = NULL;
int r;

/* this loop skips other-zone and unknown NSEC3s, also non-NSEC3 RRs */
Expand All @@ -841,7 +845,7 @@ find_covering_nsec3(struct module_env* env, struct nsec3_filter* flt,
if(r == 0) {
log_err("nsec3: malloc failure");
break; /* alloc failure */
} else if(r < 0)
} else if(r != 1)
continue; /* malformed NSEC3 */
else if(nsec3_covers(flt->zone, hash, s, i_rr,
env->scratch_buffer)) {
Expand Down

0 comments on commit 75b8b8c

Please sign in to comment.