Skip to content

Commit 995bb81

Browse files
Arpit-Gupta-CSbagder
authored andcommitted
replace: add NULL checks for memdupzero/memdupdec return values
Both memdupzero() and memdupdec() can return NULL on allocation failure. The call site in replace() dereferenced them unconditionally, which would crash on out-of-memory. Add NULL checks and call errorf() on failure, consistent with the rest of the codebase.
1 parent ed30ae6 commit 995bb81

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

trurl.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1662,6 +1662,11 @@ static bool replace(struct option *o)
16621662
pdec = memdupdec(key.str, key.len + value.len + 1, o->jsonout);
16631663
p = memdupzero(key.str, key.len + value.len + (value.str ? 1 : 0),
16641664
&query_is_modified);
1665+
if(!p || !pdec) {
1666+
free(pdec);
1667+
free(p);
1668+
errorf(o, ERROR_MEM, "out of memory");
1669+
}
16651670
qpairs[i].len = p->len;
16661671
qpairs[i].str = p->str;
16671672
qpairsdec[i].len = pdec->len;

0 commit comments

Comments
 (0)