diff options
author | Emanuele Torre <torreemanuele6@gmail.com> | 2023-10-21 23:27:40 +0200 |
---|---|---|
committer | Nico Williams <nico@cryptonector.com> | 2023-10-22 10:51:24 -0500 |
commit | e85e3582330af543f1a7b293c6b9b27f342670a2 (patch) | |
tree | 4351e7fb171a17f6a632c2e2e93d2bd8afad9b25 /src | |
parent | 7ab117a483e127006f30efa818a7a8281077ec72 (diff) |
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 <kn@openbsd.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/main.c | 5 |
1 files changed, 3 insertions, 2 deletions
@@ -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; @@ -344,7 +345,7 @@ int main(int argc, char* argv[]) { jq = jq_init(); if (jq == NULL) { - perror("malloc"); + perror("jq_init"); ret = JQ_ERROR_SYSTEM; goto out; } @@ -352,7 +353,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; |