From b52fc1043b045a3c5004be7eb85a15d3a055e9a4 Mon Sep 17 00:00:00 2001 From: Nicolas Williams Date: Tue, 26 Mar 2019 18:33:19 -0500 Subject: [PATCH] Fix assert in generator subexpressions (fix #1875) Expressions of the form `path(EXPR) | select(GENERATOR)`, where `EXPR` is a path expression and `GENERATOR` is a generator conditional expression (e.g., `has("a"), has("b")`) cause an assertion if the jq_state VM is torn down too soon. That assert() was only correct if assuming that the conditional is not a generator. If the conditional is generator, then what we see is that when backtracking a SUBEXP_END is executed without a corresponding SUBEXP_BEGIN because the entire conditional is bracketed with SUBEXP_BEGIN and SUBEXP_END, and since it's resumed in the middle, in between the brackets. Rather than assert that the jq->path_len being restored has some particular value, we can simply re-compute it from the restored jq->path. --- src/execute.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/execute.c b/src/execute.c index d7a9615..65c6bc7 100644 --- a/src/execute.c +++ b/src/execute.c @@ -292,7 +292,7 @@ uint16_t* stack_restore(jq_state *jq){ assert(path_len >= 0); jq->path = jv_array_slice(jq->path, 0, path_len); } else { - assert(path_len == 0); + fork->path_len = 0; } jv_free(jq->value_at_path); jq->value_at_path = fork->value_at_path; -- 2.49.0