{"thread":{"id":"64763","subject":"[PATCH][next] hook: check for NULL pointer before deref","startedAt":"2026-01-09T15:36:07Z","lastAt":"2026-01-09T15:57:35Z","messageCount":3,"participants":["Adrian Ratiu","Patrick Steinhardt"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"533381","messageId":"20260109153528.476163-1-adrian.ratiu@collabora.com","threadId":"64763","inReplyTo":null,"subject":"[PATCH][next] hook: check for NULL pointer before deref","fromName":"Adrian Ratiu","fromEmail":"adrian.ratiu@collabora.com","sentAt":"2026-01-09T15:35:28Z","receivedAt":"2026-01-09T15:36:07Z","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.\nSuccesful CI run: https://github.com/10ne1/git/actions/runs/20855922803\n---\n hook.c | 7 ++++---\n 1 file changed, 4 insertions(+), 3 deletions(-)\n\ndiff --git a/hook.c b/hook.c\nindex 35211e5ed7..c257bd3940 100644\n--- a/hook.c\n+++ b/hook.c\n@@ -148,12 +148,11 @@ 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@@ -165,11 +164,13 @@ int run_hooks_opt(struct repository *r, const char *hook_name,\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+\n \tif (options->invoked_hook)\n \t\t*options->invoked_hook = 0;\n \n-- \n2.51.2\n\n"},{"id":"533382","messageId":"aWEkCqABozBzT-QS@pks.im","threadId":"64763","inReplyTo":"20260109153528.476163-1-adrian.ratiu@collabora.com","subject":"Re: [PATCH][next] hook: check for NULL pointer before deref","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-01-09T15:51:38Z","receivedAt":"2026-01-09T15:51:44Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Fri, Jan 09, 2026 at 05:35:28PM +0200, Adrian Ratiu wrote:\n> diff --git a/hook.c b/hook.c\n> index 35211e5ed7..c257bd3940 100644\n> --- a/hook.c\n> +++ b/hook.c\n> @@ -148,12 +148,11 @@ 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\nWhat's omitted here is that the next two lines also dereference\n`options`. That'll also have to be fixed for the warning to go away.\n\nPatrick\n"},{"id":"533383","messageId":"87ecnywzhd.fsf@collabora.com","threadId":"64763","inReplyTo":"aWEkCqABozBzT-QS@pks.im","subject":"Re: [PATCH][next] hook: check for NULL pointer before deref","fromName":"Adrian Ratiu","fromEmail":"adrian.ratiu@collabora.com","sentAt":"2026-01-09T15:57:18Z","receivedAt":"2026-01-09T15:57:35Z","isPatch":true,"sender":{"key":"adrian.ratiu@collabora.com","avatar":"https://avatars.githubusercontent.com/u/12472556?v=4"},"body":"On Fri, 09 Jan 2026, Patrick Steinhardt <ps@pks.im> wrote:\n> On Fri, Jan 09, 2026 at 05:35:28PM +0200, Adrian Ratiu wrote:\n>> diff --git a/hook.c b/hook.c\n>> index 35211e5ed7..c257bd3940 100644\n>> --- a/hook.c\n>> +++ b/hook.c\n>> @@ -148,12 +148,11 @@ 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>\n> What's omitted here is that the next two lines also dereference\n> `options`. That'll also have to be fixed for the warning to go away.\n\nThanks for spotting this. Will fix in the same way.\n"}]}