From 4dfb9a5787b1554280807aaa28687f6c1a0d2db6 Mon Sep 17 00:00:00 2001 From: dev Date: Sat, 14 Nov 2026 00:21:48 +0000 Subject: The two git calls were missing their NULL, so every push cost one level too much execvp walks argv until it finds a NULL. head_ref built a four-element array and fast_forward a five-element one, filled every slot, and never wrote the terminator - so the fifth and sixth entries were whatever the stack happened to be holding, and the exec either failed or ran something that was not the argument list anybody meant. Both answers were load-bearing, and both failures were silent: symbolic-ref fails the hook cannot tell which branch HEAD is, so it charges every deletion the most: admin merge-base fails the update cannot be shown to be a fast-forward, so it costs force Together that meant a user with write could create a branch and then never update it, and nobody but an admin could delete anything - with the refusal pointing at the policy, which was fine, and at a level the user did not hold, which looked deliberate. It was not. It was the shape of a C array. Fixed by writing the arrays out with their NULL visible, and commented, because the compiler will not catch this one: the array is big enough, the types are right, and the bug is in the element that is not there. The core suite could not see this, and that was the real problem - it passes --ff and --head precisely so that it needs no git, which leaves the asking itself untested. So there is now a stand-in named git in the suite, and the real one kept out of PATH: it answers symbolic-ref to order and exits merge-base either way, which covers fast-forward and non-fast-forward, HEAD's branch and not, and the case with no git at all, where the hook must fail toward denying rather than toward guessing. Eight checks, all of which failed before the fix. The container suite caught this by being the only suite that runs the real thing, which is worth noting for the next time someone suggests the integration suite is the slow one that can be skipped. --- src/hook.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'src/hook.c') diff --git a/src/hook.c b/src/hook.c index d4d801b..d581bc8 100644 --- a/src/hook.c +++ b/src/hook.c @@ -135,7 +135,11 @@ static int object_id_ok(const char *s) static char *head_ref(hook_opts o, int *unknown) { - const char *argv[4]; + /* Terminated by hand, and by name: execvp walks this array until it finds + * the NULL, and an array that runs off the end takes whatever is on the + * stack next as an argument - which is not a crash you can read, and made + * every deletion cost admin because the answer was never received. */ + const char *argv[5] = { "git", "symbolic-ref", "-q", "HEAD", NULL }; char *out = NULL; int rc; @@ -147,10 +151,6 @@ static char *head_ref(hook_opts o, int *unknown) if (!o.use_git) return NULL; /* told not to ask, so do not guess either way */ - argv[0] = "git"; - argv[1] = "symbolic-ref"; - argv[2] = "-q"; - argv[3] = "HEAD"; rc = spawn(argv, 1, &out); if (rc == 0 && out != NULL && out[0] != '\0') return out; @@ -162,7 +162,9 @@ static char *head_ref(hook_opts o, int *unknown) /* Is old an ancestor of new? */ static int fast_forward(hook_opts o, const char *old, const char *new) { - const char *argv[5]; + /* Same as head_ref: the NULL is part of the contract, not padding. */ + const char *argv[6] = { "git", "merge-base", "--is-ancestor", + NULL, NULL, NULL }; int rc; if (strcmp(o.ff, "yes") == 0) @@ -172,9 +174,6 @@ static int fast_forward(hook_opts o, const char *old, const char *new) if (!o.use_git) return 0; - argv[0] = "git"; - argv[1] = "merge-base"; - argv[2] = "--is-ancestor"; argv[3] = old; argv[4] = new; rc = spawn(argv, 0, NULL); -- cgit v1.2.3