Skip to content

Commit

Permalink
Fix possible uninitialised value dereference if jq_init() fails
Browse files Browse the repository at this point in the history
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: #2934 (comment)

Reported-By: Klemens Nanni <kn@openbsd.org>
  • Loading branch information
emanuele6 authored and nicowilliams committed Oct 22, 2023
1 parent 7ab117a commit e85e358
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -344,15 +345,15 @@ int main(int argc, char* argv[]) {

jq = jq_init();
if (jq == NULL) {
perror("malloc");
perror("jq_init");
ret = JQ_ERROR_SYSTEM;
goto out;
}

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;
Expand Down

0 comments on commit e85e358

Please sign in to comment.