1
0
mirror of https://github.com/stedolan/jq.git synced 2024-05-11 05:55:39 +00:00

Fix crash in LOADVN when stack grows

This `stack_push()` call in LOADVN invalidates `var`:

       jv* var = frame_local_var(jq, v, level);
       jv_free(stack_popn(jq));
------>stack_push(jq, *var);
       *var = jv_null();
       ^^^^^^

We have to re-compute `var`:

       jv* var = frame_local_var(jq, v, level);
       jv_free(stack_popn(jq));
       stack_push(jq, *var);
------>var = frame_local_var(jq, v, level);
       *var = jv_null();
This commit is contained in:
Nicolas Williams
2021-10-21 00:10:47 -05:00
parent 07dc653ae1
commit 582717a7b4

View File

@@ -561,7 +561,11 @@ jv jq_next(jq_state *jq) {
printf(" (%d)\n", jv_get_refcnt(*var));
}
jv_free(stack_popn(jq));
// This `stack_push()` invalidates the `var` reference, so
stack_push(jq, *var);
// we have to re-resolve `var` before we can set it to null
var = frame_local_var(jq, v, level);
*var = jv_null();
break;
}