Commit 1be2de2
packed-backend: check whether the refname contains NULL binaries
We have already implemented the header consistency check for the raw
"packed-refs" file. Before we implement the consistency check for each
ref entry, let's analysis [1] which reports that "git fsck" cannot
detect some binary zeros.
"packed-backend.c::next_record" will use "check_refname_format" to check
the consistency of the refname. If it is not OK, the program will die.
So, we already have the code path and we must miss out something.
We use the following code to get the refname:
strbuf_add(&iter->refname_buf, p, eol - p);
iter->base.refname = iter->refname_buf.buf
In the above code, `p` is the start pointer of the refname and `eol` is
the next newline pointer. We calculate the length of the refname by
subtracting the two pointers. Then we add the memory range between `p`
and `eol` to get the refname.
However, if there are some NULL binaries in the memory range between `p`
and `eol`, we will see the refname as a valid ref name as long as the
memory range between `p` and the first occurred NULL binary is valid.
In order to catch above corruption, create a new function
"refname_contains_null" by checking whether the "refname.len" equals to
the length of the raw string pointer "refname.buf". If not equal, there
must be some NULL binaries in the refname.
Use this function in "next_record" function to die the program if
"refname_contains_null" returns true.
[1] https://lore.kernel.org/git/[email protected]/
Reported-by: R. Diez <[email protected]>
Mentored-by: Patrick Steinhardt <[email protected]>
Mentored-by: Karthik Nayak <[email protected]>
Signed-off-by: shejialuo <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>1 parent e859555 commit 1be2de2
1 file changed
+20
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
494 | 494 | | |
495 | 495 | | |
496 | 496 | | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
497 | 514 | | |
498 | 515 | | |
499 | 516 | | |
| |||
895 | 912 | | |
896 | 913 | | |
897 | 914 | | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
898 | 918 | | |
899 | 919 | | |
900 | 920 | | |
| |||
0 commit comments