{"thread":{"id":"64764","subject":"[PATCH v2][next] hook: check for NULL pointer before deref","startedAt":"2026-01-09T18:19:42Z","lastAt":"2026-01-11T14:12:35Z","messageCount":3,"participants":["Adrian Ratiu","Junio C Hamano"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"533399","messageId":"20260109181912.689409-1-adrian.ratiu@collabora.com","threadId":"64764","inReplyTo":null,"subject":"[PATCH v2][next] hook: check for NULL pointer before deref","fromName":"Adrian Ratiu","fromEmail":"adrian.ratiu@collabora.com","sentAt":"2026-01-09T18:19:12Z","receivedAt":"2026-01-09T18:19:42Z","isPatch":true,"sender":{"key":"adrian.ratiu@collabora.com","avatar":"https://avatars.githubusercontent.com/u/12472556?v=4"},"body":"Fix a compiler warning (-Werror=analyzer-deref-before-check) due to\ndereferencing the options pointer before NULL checking it.\n\nIn practice run_hooks_opt() is never called with a NULL opt struct,\nso this just fixes the code to not trigger the warning anymore.\n\nThe NULL check is kept as-is because some future patches might end up\ncalling run_hooks_opt with a NULL opt struct, which is clearly a bug.\n\nWhile at it, also fix the BUG message function name.\n\nReported-by: correctmost <cmlists@sent.com>\nSuggested-by: Patrick Steinhardt <ps@pks.im>\nSigned-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>\n---\nThis is based on next, because it fixes a warning introduced in next.\n\nChanges in v2:\n* Applied fix to two additional dereferences (Patrick)\n\nSuccesful CI run: https://github.com/10ne1/git/actions/runs/20859773595\n---\n hook.c | 11 ++++++-----\n 1 file changed, 6 insertions(+), 5 deletions(-)\n\ndiff --git a/hook.c b/hook.c\nindex 35211e5ed7..6b8ddfe7b6 100644\n--- a/hook.c\n+++ b/hook.c\n@@ -148,28 +148,29 @@ int run_hooks_opt(struct repository *r, const char *hook_name,\n \t};\n \tconst char *const hook_path = find_hook(r, hook_name);\n \tint ret = 0;\n-\tconst struct run_process_parallel_opts opts = {\n+\tstruct run_process_parallel_opts opts = {\n \t\t.tr2_category = \"hook\",\n \t\t.tr2_label = hook_name,\n \n \t\t.processes = 1,\n-\t\t.ungroup = options->ungroup,\n \n \t\t.get_next_task = pick_next_hook,\n \t\t.start_failure = notify_start_failure,\n-\t\t.feed_pipe = options->feed_pipe,\n-\t\t.consume_output = options->consume_output,\n \t\t.task_finished = notify_hook_finished,\n \n \t\t.data = &cb_data,\n \t};\n \n \tif (!options)\n-\t\tBUG(\"a struct run_hooks_opt must be provided to run_hooks\");\n+\t\tBUG(\"a struct run_hooks_opt must be provided to run_hooks_opt\");\n \n \tif (options->path_to_stdin && options->feed_pipe)\n \t\tBUG(\"options path_to_stdin and feed_pipe are mutually exclusive\");\n \n+\topts.ungroup = options->ungroup;\n+\topts.feed_pipe = options->feed_pipe;\n+\topts.consume_output = options->consume_output;\n+\n \tif (options->invoked_hook)\n \t\t*options->invoked_hook = 0;\n \n-- \n2.51.2\n\n"},{"id":"533468","messageId":"xmqq344etd9v.fsf@gitster.g","threadId":"64764","inReplyTo":"20260109181912.689409-1-adrian.ratiu@collabora.com","subject":"Re: [PATCH v2][next] hook: check for NULL pointer before deref","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-01-10T02:25:16Z","receivedAt":"2026-01-10T02:25:19Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Adrian Ratiu <adrian.ratiu@collabora.com> writes:\n\n> Fix a compiler warning (-Werror=analyzer-deref-before-check) due to\n> dereferencing the options pointer before NULL checking it.\n>\n> In practice run_hooks_opt() is never called with a NULL opt struct,\n> so this just fixes the code to not trigger the warning anymore.\n>\n> The NULL check is kept as-is because some future patches might end up\n> calling run_hooks_opt with a NULL opt struct, which is clearly a bug.\n>\n> While at it, also fix the BUG message function name.\n>\n> Reported-by: correctmost <cmlists@sent.com>\n> Suggested-by: Patrick Steinhardt <ps@pks.im>\n> Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>\n> ---\n> This is based on next, because it fixes a warning introduced in next.\n\nActually the problematic topic has been in 'master' for a few days\nalready, isn't it?  I'd apply directly on top of ar/run-comand-hook\ntopic.\n\nThanks.\n"},{"id":"533525","messageId":"87ecnws0fx.fsf@gentoo.mail-host-address-is-not-set","threadId":"64764","inReplyTo":"xmqq344etd9v.fsf@gitster.g","subject":"Re: [PATCH v2][next] hook: check for NULL pointer before deref","fromName":"Adrian Ratiu","fromEmail":"adrian.ratiu@collabora.com","sentAt":"2026-01-11T14:12:18Z","receivedAt":"2026-01-11T14:12:35Z","isPatch":true,"sender":{"key":"adrian.ratiu@collabora.com","avatar":"https://avatars.githubusercontent.com/u/12472556?v=4"},"body":"On Fri, 09 Jan 2026, Junio C Hamano <gitster@pobox.com> wrote:\n> Adrian Ratiu <adrian.ratiu@collabora.com> writes:\n>\n>> Fix a compiler warning (-Werror=analyzer-deref-before-check) due to\n>> dereferencing the options pointer before NULL checking it.\n>>\n>> In practice run_hooks_opt() is never called with a NULL opt struct,\n>> so this just fixes the code to not trigger the warning anymore.\n>>\n>> The NULL check is kept as-is because some future patches might end up\n>> calling run_hooks_opt with a NULL opt struct, which is clearly a bug.\n>>\n>> While at it, also fix the BUG message function name.\n>>\n>> Reported-by: correctmost <cmlists@sent.com>\n>> Suggested-by: Patrick Steinhardt <ps@pks.im>\n>> Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>\n>> ---\n>> This is based on next, because it fixes a warning introduced in next.\n>\n> Actually the problematic topic has been in 'master' for a few days\n> already, isn't it?  I'd apply directly on top of ar/run-comand-hook\n> topic.\n\nYes, that is correct, the commits landed in master so this patch applies\ncleanly there as well (just double checked to confirm). Thanks!\n"}]}