Skip to content
Myr

jv_setpath: fix leak when indexing an array with an array

Before adoption: this commit came in with the history the project adopted, so no landing records it.

arrays[arrays] is a special case of "INDEX" that actually returns an array containing the indices in which the array that is being indexed contains the start of the key array. So array keys, for array values, are a kind of key that can be "got", but not "set". jv_setpath() was not freeing the value it "got" from indexing that key, in case the following "set" on that key failed, resulting in a leak. $ ./jq -n '[] | setpath([[1]]; 1)' jq: error (at <unknown>): Cannot update field at array index of array ================================================================= ==953483==ERROR: LeakSanitizer: detected memory leaks Direct leak of 272 byte(s) in 1 object(s) allocated from: #0 0x725f4d4e1359 in __interceptor_malloc /usr/src/debug/gcc/gcc/libsanitizer/asan/asan_malloc_linux.cpp:69 #1 0x5ec17b1a7438 in jv_mem_alloc src/jv_alloc.c:141 SUMMARY: AddressSanitizer: 272 byte(s) leaked in 1 allocation(s). Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=66061

authored by Emanuele Torre · committed by GitHub · parent afe0afa · Browse files · 2 files+8 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+8 added−0 removed

  • tests:+7 added−0 removed
  • other:+1 added−0 removed

2 files+8 added−0 removed

modified:src/jv_aux.c+1 added
415 unmodified lines
416 // To avoid the extra copy we drop the reference from `root` by setting that417 // to null first.418 root = jv_set(root, jv_copy(pathcurr), jv_null());419 if (!jv_is_valid(root)) {420 jv_free(subroot);421 jv_free(pathcurr);422 jv_free(pathrest);423 jv_free(value);424 return root;
305 unmodified lines
modified:tests/jq.test+7 added
2167 unmodified lines
2168["ko","endswith() requires string inputs"]2169["ko","endswith() requires string inputs"]2170["ok",""]2171["ko","endswith() requires string inputs"]217221732174# oss-fuzz #66061: setpath/2 leaks when indexing array with array21752176try ["OK", setpath([[1]]; 1)] catch ["KO", .]2177[]2178["KO","Cannot update field at array index of array"]