Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit aca4608

Browse files
committedOct 22, 2023
Fix possible uninitialised value dereference if jq_init() fails
If jq_init() fails, goto out would try to free input_state which is uninitialised. I initialised input_state to NULL to fix the problem. Ref: jqlang#2934 (comment) Reported-By: Klemens Nanni <kn@openbsd.org>
1 parent 9de0e26 commit aca4608

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed
 

‎src/main.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ int umain(int argc, char* argv[]) {
310310
int main(int argc, char* argv[]) {
311311
#endif
312312
jq_state *jq = NULL;
313+
jq_util_input_state *input_state = NULL;
313314
int ret = JQ_OK_NO_OUTPUT;
314315
int compiled = 0;
315316
int parser_flags = 0;
@@ -336,15 +337,15 @@ int main(int argc, char* argv[]) {
336337

337338
jq = jq_init();
338339
if (jq == NULL) {
339-
perror("malloc");
340+
perror("jq_init");
340341
ret = JQ_ERROR_SYSTEM;
341342
goto out;
342343
}
343344

344345
int dumpopts = JV_PRINT_INDENT_FLAGS(2);
345346
const char* program = 0;
346347

347-
jq_util_input_state *input_state = jq_util_input_init(NULL, NULL); // XXX add err_cb
348+
input_state = jq_util_input_init(NULL, NULL); // XXX add err_cb
348349

349350
int further_args_are_strings = 0;
350351
int further_args_are_json = 0;

0 commit comments

Comments
 (0)
Please sign in to comment.