Skip to content

Commit

Permalink
ccan: Add freed pointer checking to delete strset member
Browse files Browse the repository at this point in the history
Add to set freed entry pointer to NULL then check it if NULL.

Signed-off-by: Tokunori Ikegami <[email protected]>
  • Loading branch information
ikegami-t committed Feb 23, 2024
1 parent 90ee4ee commit 87ec662
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions ccan/ccan/strset/strset.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ char *strset_del(struct strset *set, const char *member)

/* Sew empty string back so remaining logic works */
free(n->u.n);
n->u.n = NULL;
n->u.s = empty_str;
break;
}
Expand All @@ -202,13 +203,14 @@ char *strset_del(struct strset *set, const char *member)
if (n->u.n->byte_num < len) {
c = bytes[n->u.n->byte_num];
direction = (c >> n->u.n->bit_num) & 1;
} else
} else {
direction = 0;
}
n = &n->u.n->child[direction];
}

/* Did we find it? */
if (!streq(member, n->u.s)) {
if (!n->u.s || !streq(member, n->u.s)) {
errno = ENOENT;
return NULL;
}
Expand Down

0 comments on commit 87ec662

Please sign in to comment.