Reject embedded NUL bytes in module import paths

jq accepts embedded NUL bytes at the language level but resolves
module import paths through NUL-terminated C strings, so the path
validated by policy or audit code could differ from the on-disk
path jq actually opens. Pass jv through gen_import so the AST
preserves the original bytes, and reject embedded NULs in
validate_relpath.

Fixes CVE-2026-43895.
This commit is contained in:
itchyny committed 2026-05-09 17:08:43 +09:00
1 parent 9761ceb7d6
commit 9d223f153c
6 files changed
+314 -309

No files matched your search

+8 -4
View File
@@ -525,13 +525,17 @@ jv block_module_meta(block b) {
return jv_null();
}
block gen_import(const char* name, const char* as, int is_data) {
block gen_import(jv name, jv as, int is_data) {
assert(jv_get_kind(name) == JV_KIND_STRING);
assert(!jv_is_valid(as) || jv_get_kind(as) == JV_KIND_STRING);
inst* i = inst_new(DEPS);
jv meta = jv_object();
if (as != NULL)
meta = jv_object_set(meta, jv_string("as"), jv_string(as));
if (jv_is_valid(as))
meta = jv_object_set(meta, jv_string("as"), as);
else
jv_free(as);
meta = jv_object_set(meta, jv_string("is_data"), is_data ? jv_true() : jv_false());
meta = jv_object_set(meta, jv_string("relpath"), jv_string(name));
meta = jv_object_set(meta, jv_string("relpath"), name);
i->imm.constant = meta;
return inst_block(i);
}