* [PATCH][next] hook: check for NULL pointer before deref
@ 2026-01-09 15:35 Adrian Ratiu
2026-01-09 15:51 ` Patrick Steinhardt
0 siblings, 1 reply; 3+ messages in thread
From: Adrian Ratiu @ 2026-01-09 15:35 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Patrick Steinhardt, Emily Shaffer, Adrian Ratiu,
correctmost
Fix a compiler warning (-Werror=analyzer-deref-before-check) due to
dereferencing the options pointer before NULL checking it.
In practice run_hooks_opt() is never called with a NULL opt struct,
so this just fixes the code to not trigger the warning anymore.
The NULL check is kept as-is because some future patches might end up
calling run_hooks_opt with a NULL opt struct, which is clearly a bug.
While at it, also fix the BUG message function name.
Reported-by: correctmost <cmlists@sent.com>
Suggested-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>
---
This is based on next, because it fixes a warning introduced in next.
Succesful CI run: https://github.com/10ne1/git/actions/runs/20855922803
---
hook.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/hook.c b/hook.c
index 35211e5ed7..c257bd3940 100644
--- a/hook.c
+++ b/hook.c
@@ -148,12 +148,11 @@ int run_hooks_opt(struct repository *r, const char *hook_name,
};
const char *const hook_path = find_hook(r, hook_name);
int ret = 0;
- const struct run_process_parallel_opts opts = {
+ struct run_process_parallel_opts opts = {
.tr2_category = "hook",
.tr2_label = hook_name,
.processes = 1,
- .ungroup = options->ungroup,
.get_next_task = pick_next_hook,
.start_failure = notify_start_failure,
@@ -165,11 +164,13 @@ int run_hooks_opt(struct repository *r, const char *hook_name,
};
if (!options)
- BUG("a struct run_hooks_opt must be provided to run_hooks");
+ BUG("a struct run_hooks_opt must be provided to run_hooks_opt");
if (options->path_to_stdin && options->feed_pipe)
BUG("options path_to_stdin and feed_pipe are mutually exclusive");
+ opts.ungroup = options->ungroup;
+
if (options->invoked_hook)
*options->invoked_hook = 0;
--
2.51.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH][next] hook: check for NULL pointer before deref
2026-01-09 15:35 [PATCH][next] hook: check for NULL pointer before deref Adrian Ratiu
@ 2026-01-09 15:51 ` Patrick Steinhardt
2026-01-09 15:57 ` Adrian Ratiu
0 siblings, 1 reply; 3+ messages in thread
From: Patrick Steinhardt @ 2026-01-09 15:51 UTC (permalink / raw)
To: Adrian Ratiu; +Cc: git, Junio C Hamano, Emily Shaffer, correctmost
On Fri, Jan 09, 2026 at 05:35:28PM +0200, Adrian Ratiu wrote:
> diff --git a/hook.c b/hook.c
> index 35211e5ed7..c257bd3940 100644
> --- a/hook.c
> +++ b/hook.c
> @@ -148,12 +148,11 @@ int run_hooks_opt(struct repository *r, const char *hook_name,
> };
> const char *const hook_path = find_hook(r, hook_name);
> int ret = 0;
> - const struct run_process_parallel_opts opts = {
> + struct run_process_parallel_opts opts = {
> .tr2_category = "hook",
> .tr2_label = hook_name,
>
> .processes = 1,
> - .ungroup = options->ungroup,
>
> .get_next_task = pick_next_hook,
> .start_failure = notify_start_failure,
What's omitted here is that the next two lines also dereference
`options`. That'll also have to be fixed for the warning to go away.
Patrick
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH][next] hook: check for NULL pointer before deref
2026-01-09 15:51 ` Patrick Steinhardt
@ 2026-01-09 15:57 ` Adrian Ratiu
0 siblings, 0 replies; 3+ messages in thread
From: Adrian Ratiu @ 2026-01-09 15:57 UTC (permalink / raw)
To: Patrick Steinhardt; +Cc: git, Junio C Hamano, Emily Shaffer, correctmost
On Fri, 09 Jan 2026, Patrick Steinhardt <ps@pks.im> wrote:
> On Fri, Jan 09, 2026 at 05:35:28PM +0200, Adrian Ratiu wrote:
>> diff --git a/hook.c b/hook.c
>> index 35211e5ed7..c257bd3940 100644
>> --- a/hook.c
>> +++ b/hook.c
>> @@ -148,12 +148,11 @@ int run_hooks_opt(struct repository *r, const char *hook_name,
>> };
>> const char *const hook_path = find_hook(r, hook_name);
>> int ret = 0;
>> - const struct run_process_parallel_opts opts = {
>> + struct run_process_parallel_opts opts = {
>> .tr2_category = "hook",
>> .tr2_label = hook_name,
>>
>> .processes = 1,
>> - .ungroup = options->ungroup,
>>
>> .get_next_task = pick_next_hook,
>> .start_failure = notify_start_failure,
>
> What's omitted here is that the next two lines also dereference
> `options`. That'll also have to be fixed for the warning to go away.
Thanks for spotting this. Will fix in the same way.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-01-09 15:57 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-09 15:35 [PATCH][next] hook: check for NULL pointer before deref Adrian Ratiu
2026-01-09 15:51 ` Patrick Steinhardt
2026-01-09 15:57 ` Adrian Ratiu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox