Skip to content

Commit

Permalink
Initialise jq.input_cb{,_data} to NULL in jq_init()
Browse files Browse the repository at this point in the history
To avoid causing segmentation faults when  input/1  is called in a
jq_state on which  jq_set_input_cb()  has not been called; e.g. the one
used by  jq --run-tests.

That segfault could also by fixed in run_jq_tests() by calling:

  jq_set_input_cb(jq, NULL, NULL);

But I think it makes sense to just make jq_init() initialise those
values to NULL.

Ref: jqlang#2717 (comment)
  • Loading branch information
emanuele6 committed Jul 15, 2023
1 parent bf43905 commit 10e3857
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,9 @@ jq_state *jq_init(void) {
jq->exit_code = jv_invalid();
jq->error_message = jv_invalid();

jq->input_cb = NULL;
jq->input_cb_data = NULL;

jq->err_cb = default_err_cb;
jq->err_cb_data = stderr;

Expand Down
7 changes: 7 additions & 0 deletions tests/jq.test
Original file line number Diff line number Diff line change
Expand Up @@ -1814,3 +1814,10 @@ true
tojson | fromjson
{"a":nan}
{"a":null}


# calling input/1 in a test doesn't crash jq

try input catch .
null
"break"

0 comments on commit 10e3857

Please sign in to comment.