| Commit message (Collapse) | Author | Age | Files | Lines |
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The comments had grown into essays. A file header explaining why the file
exists, then a paragraph above each function restating what the next eight
lines do, then a paragraph above that one explaining why that matters. The
reader gets no further than the first paragraph, and the second is the one that
goes stale: it describes code that has since changed, and nothing fails when it
does.
Cut by about half. What is left is the three things a comment can do that code
cannot: say why the constraint exists (no regex because a hook must not depend
on what might be missing at 3am), say what is not obvious from the shape (a
bare ref name is a branch, never a tag; the seventh field of /etc/passwd is the
shell), and say where it hurts (the NULL in an execvp array, the mode and owner
that have to survive an atomic rewrite, the child that must not keep the hook's
stdin).
Block comments became // lines, which is also what the other C trees here use,
and the file headers went to two or three lines. Section banners stayed: they
are navigation, not prose.
Behaviour is unchanged and the suites prove it: 171 direct checks, 162
behavioural, clean under -Werror and under ASan/UBSan.
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
A git host that anonymous-clones and shared-pushes has one question left to
answer: which human may move which ref. This answers it from one plain file,
in one binary, with no runtime beyond libc.
Four modes, because they must agree exactly about what a rule means - a check
that answers differently from the hook is a program that lies:
check one question, for an operator or a script
authorize a whole push, the way core.hooksPath hands it over: identity from
GIT_HOST_USER (ssh key option) or REMOTE_USER (http auth), and one
"old new ref" line per ref on stdin. Also runs as "pre-receive",
which is how git finds it.
validate does the policy parse, and is the host wired to run it
edit grant, revoke, protect (the deployed policy is a read-only mount on
purpose, so these are for the source copy and say so when told)
The verdict is the exit status, since the caller is a hook: 0 allowed, 1 denied,
3 no usable policy, 64 usage. A policy that cannot be read or does not parse
denies everything rather than guessing, and one bad line poisons the whole file
on purpose: a mistyped rule that quietly widens access is worse than an evening
of refused pushes.
Semantics kept from the shell engine this replaces: levels are monotone (admin
implies force implies write), rules add up rather than order, "@" is only
everyone the policy already names, protected refs cost one step more than the
action asked for, and refs that are neither branches nor tags are for admins.
"main", "heads/main" and "refs/heads/main" are one branch; a bare name is never
a tag.
Two facts a push does not carry - is old an ancestor of new, and which branch
HEAD points at - are asked of git, and an answer that cannot be had is taken the
expensive way. tests/unit.c covers the matcher directly (173 checks); the
behavioural suite that drives this the way git does follows next.
|