From aca4608b0f512b40cc2bc2a30c7137327a48c91e Mon Sep 17 00:00:00 2001 From: Emanuele Torre Date: Sat, 21 Oct 2023 23:27:40 +0200 Subject: [PATCH] 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: https://github.com/jqlang/jq/pull/2934#discussion_r1367795641 Reported-By: Klemens Nanni --- src/main.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index 226c926ce2..2aa84bde13 100644 --- a/src/main.c +++ b/src/main.c @@ -310,6 +310,7 @@ int umain(int argc, char* argv[]) { int main(int argc, char* argv[]) { #endif jq_state *jq = NULL; + jq_util_input_state *input_state = NULL; int ret = JQ_OK_NO_OUTPUT; int compiled = 0; int parser_flags = 0; @@ -336,7 +337,7 @@ int main(int argc, char* argv[]) { jq = jq_init(); if (jq == NULL) { - perror("malloc"); + perror("jq_init"); ret = JQ_ERROR_SYSTEM; goto out; } @@ -344,7 +345,7 @@ int main(int argc, char* argv[]) { int dumpopts = JV_PRINT_INDENT_FLAGS(2); const char* program = 0; - jq_util_input_state *input_state = jq_util_input_init(NULL, NULL); // XXX add err_cb + input_state = jq_util_input_init(NULL, NULL); // XXX add err_cb int further_args_are_strings = 0; int further_args_are_json = 0;