Commit 5413b07
committed
refs: enforce name conventions for root refs
We recently taught check_refname_format() to insist that any ref outside
of "refs/" match the is_root_ref_syntax() rules. This can reduce the
chance of accidentally reading or writing a non-ref file in ".git" when
the files backend is in use.
For case-sensitive filesystems, this should mostly work. We do not
generally create all-caps files under .git/ unless they are meant to be
root refs.
But for case-insensitive filesystems, it's less clear. Asking to write
to "CONFIG" would try to access the actual ".git/config" file (though
fortunately this does not work, as we refuse to write anything we can't
parse as a ref).
We already have functions that catalog the pattern of allowable names
(i.e., ending in "_HEAD" or one of a set of historical exceptions). So
even if we allowed creating such a ref, we'd skip over it while
iterating over the root refs. But we don't enforce those rules; we check
only the "all caps and underscore" syntax rule, not the full root-ref
rules.
Let's teach check_refname_format() to use those functions to further
restrict what it will allow at the root level. That should make things
safer and more consistent with ref iteration. Note that while
is_root_ref_syntax() covers the syntax for both regular root refs and
pseudo-refs (FETCH_HEAD and MERGE_HEAD), the is_root_ref() function does
not include pseudo-refs. So we have to check the two classes separately.
This patch doesn't touch refname_is_safe(), which generally tries to be
a bit more loose (e.g., to allow deletion of bogus names). I've left it
loose here, though arguably it would benefit from some of the same
protection (you wouldn't want to delete ".git/config" either, though
again, we'd refuse to delete something we can't parse).1 parent c8fa5cd commit 5413b07
2 files changed
+12
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
283 | 283 | | |
284 | 284 | | |
285 | 285 | | |
286 | | - | |
| 286 | + | |
| 287 | + | |
287 | 288 | | |
288 | 289 | | |
289 | 290 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
399 | 399 | | |
400 | 400 | | |
401 | 401 | | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
402 | 407 | | |
403 | 408 | | |
404 | 409 | | |
| |||
409 | 414 | | |
410 | 415 | | |
411 | 416 | | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
412 | 422 | | |
0 commit comments