Skip to content

Commit

Permalink
jv_setpath()+setpath/2: don't leak the input after an invalid get
Browse files Browse the repository at this point in the history
  • Loading branch information
emanuele6 authored Dec 10, 2023
1 parent 80bc768 commit 6b69ffe
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/jv_aux.c
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ jv jv_setpath(jv root, jv path, jv value) {

jv subroot = jv_get(jv_copy(root), jv_copy(pathcurr));
if (!jv_is_valid(subroot)) {
jv_free(root);
jv_free(pathcurr);
jv_free(pathrest);
jv_free(value);
Expand Down
4 changes: 4 additions & 0 deletions tests/jq.test
Original file line number Diff line number Diff line change
Expand Up @@ -2091,3 +2091,7 @@ try ("foobar" | .[1.5]) catch .
null
"Cannot index string with number"

# setpath/2 does not leak the input after an invalid get #2967
try ["ok", setpath([1]; 1)] catch ["ko", .]
{"hi":"hello"}
["ko","Cannot index object with number"]

0 comments on commit 6b69ffe

Please sign in to comment.