Skip to content
Myr

Fix NUL truncation in program files loaded with -f

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

This fixes CVE-2026-41256.

authored by itchyny · committed by itchyny · parent 01b3cde · Browse files · 2 files+15 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+15 added−0 removed

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

2 files+15 added−0 removed

modified:src/main.c+8 added
610 unmodified lines
611 jv_free(data);612 ret = JQ_ERROR_SYSTEM;613 goto out;614 }615 int len = jv_string_length_bytes(jv_copy(data));616 if ((size_t)len != strlen(jv_string_value(data))) {617 fprintf(stderr, "jq: program file contains NUL bytes\n");618 free(program_origin);619 jv_free(data);620 ret = JQ_ERROR_SYSTEM;621 goto out;622 }623 jq_set_attr(jq, jv_string("PROGRAM_ORIGIN"), jq_realpath(jv_string(dirname(program_origin))));624 ARGS = JV_OBJECT(jv_string("positional"), ARGS,625 jv_string("named"), jv_copy(program_arguments));626 program_arguments = jv_object_set(program_arguments, jv_string("ARGS"), jv_copy(ARGS));
104 unmodified lines
modified:tests/shtest+7 added
884 unmodified lines
885 printf 'Error expected but jq exited successfully\n' 1>&2886 exit 1887fi888889# CVE-2026-41256: No NUL truncation in program files loaded with -f890printf '.\x00invalid' > "$d/nul_prog.jq"891if echo '42' | $JQ -f "$d/nul_prog.jq" >/dev/null 2>/dev/null; then892 printf 'Error expected for program file with NUL bytes\n' 1>&2893 exit 1894fi895896exit 0