]> git.ipfire.org Git - thirdparty/git.git/blobdiff - hook.c
hooks: fix an obscure TOCTOU "did we just run a hook?" race
[thirdparty/git.git] / hook.c
diff --git a/hook.c b/hook.c
index 69a215b2c3c2c3b95a799a56325de9111873b39e..1d51be3b77a713bcd45428988c97841156a513cf 100644 (file)
--- a/hook.c
+++ b/hook.c
@@ -96,9 +96,13 @@ static int notify_hook_finished(int result,
                                void *pp_task_cb)
 {
        struct hook_cb_data *hook_cb = pp_cb;
+       struct run_hooks_opt *opt = hook_cb->options;
 
        hook_cb->rc |= result;
 
+       if (opt->invoked_hook)
+               *opt->invoked_hook = 1;
+
        return 0;
 }
 
@@ -123,6 +127,9 @@ int run_hooks_opt(const char *hook_name, struct run_hooks_opt *options)
        if (!options)
                BUG("a struct run_hooks_opt must be provided to run_hooks");
 
+       if (options->invoked_hook)
+               *options->invoked_hook = 0;
+
        if (!hook_path && !options->error_if_missing)
                goto cleanup;