diff --git a/src/compile.c b/src/compile.c index b925020a..e1780b9a 100644 --- a/src/compile.c +++ b/src/compile.c @@ -1306,12 +1306,18 @@ static int compile(struct bytecode* bc, block b, struct locfile* lf, jv args, jv bc->nsubfunctions = 0; bc->subfunctions = 0; } + if (errors) { + bc->code = 0; + bc->constants = jv_invalid(); + block_free(b); + return errors; + } uint16_t* code = jv_mem_calloc(bc->codelen, sizeof(uint16_t)); bc->code = code; pos = 0; jv constant_pool = jv_array(); int maxvar = -1; - if (!errors) for (inst* curr = b.first; curr; curr = curr->next) { + for (inst* curr = b.first; curr; curr = curr->next) { const struct opcode_description* op = opcode_describe(curr->op); if (op->length == 0) continue; diff --git a/tests/shtest b/tests/shtest index cde88152..8f3e0f63 100755 --- a/tests/shtest +++ b/tests/shtest @@ -952,6 +952,20 @@ $JQ -nf $d/prog.jq 2> $d/out && { } diff $d/out $d/expected +# Test 3: Too many function parameters in a nested function (issue #3661) +echo "Testing function parameter limit in a nested function..." +cat > $d/expected < $d/prog.jq +$JQ -nf $d/prog.jq 2> $d/out && { + echo "Expected compile error for too many parameters in a nested function" + exit 1 +} +diff $d/out $d/expected + # CVE-2026-33948: No NUL truncation in the JSON parser if printf '{}\x00{}' | $JQ >/dev/null 2> /dev/null; then printf 'Error expected but jq exited successfully\n' 1>&2