Fix crash when importing a module with errors twice (#3497)
When a module fails to parse as a library, `load_library` cached the invalid block. A second import/include of the same module would find the cached invalid block and pass it to `block_bind_library`, triggering the assertion failure. Skip caching the block when there are parse errors to avoid this problem.
This commit is contained in:
1 parent
ed3c7f214b
commit
3cd7e0da00
1 file changed
+7
-5
+7
-5
@@ -366,11 +366,13 @@ static int load_library(jq_state *jq, jv lib_path, int is_data, int raw, int opt
|
|||||||
program = block_bind_self(program, OP_IS_CALL_PSEUDO);
|
program = block_bind_self(program, OP_IS_CALL_PSEUDO);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
state_idx = lib_state->ct++;
|
if (nerrors == 0) {
|
||||||
lib_state->names = jv_mem_realloc(lib_state->names, lib_state->ct * sizeof(const char *));
|
state_idx = lib_state->ct++;
|
||||||
lib_state->defs = jv_mem_realloc(lib_state->defs, lib_state->ct * sizeof(block));
|
lib_state->names = jv_mem_realloc(lib_state->names, lib_state->ct * sizeof(const char *));
|
||||||
lib_state->names[state_idx] = strdup(jv_string_value(lib_path));
|
lib_state->defs = jv_mem_realloc(lib_state->defs, lib_state->ct * sizeof(block));
|
||||||
lib_state->defs[state_idx] = program;
|
lib_state->names[state_idx] = strdup(jv_string_value(lib_path));
|
||||||
|
lib_state->defs[state_idx] = program;
|
||||||
|
}
|
||||||
out:
|
out:
|
||||||
*out_block = program;
|
*out_block = program;
|
||||||
jv_free(lib_path);
|
jv_free(lib_path);
|
||||||
|
|||||||
Reference in new issue
Block a user