From e79335e3a587d77954face2137fc3d4b5482129e Mon Sep 17 00:00:00 2001 From: Emanuele Torre Date: Sat, 15 Jul 2023 08:11:41 +0200 Subject: [PATCH] Initialise jq_state->input_cb{,_data} to NULL in jq_init() 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 be 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: https://github.com/jqlang/jq/pull/2717#discussion_r1264338841 --- src/execute.c | 3 +++ tests/jq.test | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/src/execute.c b/src/execute.c index e1894aa5..b6810dd8 100644 --- a/src/execute.c +++ b/src/execute.c @@ -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; diff --git a/tests/jq.test b/tests/jq.test index ebaefdb8..21eabb06 100644 --- a/tests/jq.test +++ b/tests/jq.test @@ -1818,3 +1818,10 @@ true tojson | fromjson {"a":nan} {"a":null} + + +# calling input/1 in a test doesn't crash jq + +try input catch . +null +"break"