mirror of
https://git.proxmox.com/git/libgit2
synced 2025-08-06 08:24:01 +00:00
refs: loosen the OID parsing
We used to require loose references to contain only an OID (possibly after trimming the string). This is however not enough for letting us lookup FETCH_HEAD, which can have a lot of content after the initial OID. Change the parsing rules so that a loose refernce must e at least 40 bytes long and the 41st (if it's there) must be accepted by isspace(3). This makes the trim unnecessary, so only do it for symrefs. This fixes #977.
This commit is contained in:
parent
9d9288f417
commit
47f44b6ee4
21
src/refs.c
21
src/refs.c
@ -155,11 +155,26 @@ static int loose_parse_symbolic(git_reference *ref, git_buf *file_content)
|
||||
|
||||
static int loose_parse_oid(git_oid *oid, git_buf *file_content)
|
||||
{
|
||||
/* File format: 40 chars (OID) */
|
||||
if (git_buf_len(file_content) == GIT_OID_HEXSZ &&
|
||||
git_oid_fromstr(oid, git_buf_cstr(file_content)) == 0)
|
||||
size_t len;
|
||||
const char *str;
|
||||
|
||||
len = git_buf_len(file_content);
|
||||
if (len < GIT_OID_HEXSZ)
|
||||
goto corrupted;
|
||||
|
||||
/* str is guranteed to be zero-terminated */
|
||||
str = git_buf_cstr(file_content);
|
||||
|
||||
/* If the file is longer than 40 chars, the 41st must be a space */
|
||||
if (git_oid_fromstr(oid, git_buf_cstr(file_content)) < 0)
|
||||
goto corrupted;
|
||||
|
||||
/* If the file is longer than 40 chars, the 41st must be a space */
|
||||
str += GIT_OID_HEXSZ;
|
||||
if (*str == '\0' || git__isspace(*str))
|
||||
return 0;
|
||||
|
||||
corrupted:
|
||||
giterr_set(GITERR_REFERENCE, "Corrupted loose reference file");
|
||||
return -1;
|
||||
}
|
||||
|
@ -212,6 +212,7 @@ void test_refs_read__trailing(void)
|
||||
cl_git_pass(git_reference_lookup(&test, g_repo, "refs/heads/test"));
|
||||
cl_git_pass(git_reference_lookup(&trailing, g_repo, "refs/heads/trailing"));
|
||||
cl_git_pass(git_oid_cmp(git_reference_oid(test), git_reference_oid(trailing)));
|
||||
cl_git_pass(git_reference_lookup(&trailing, g_repo, "FETCH_HEAD"));
|
||||
|
||||
git_reference_free(test);
|
||||
git_reference_free(trailing);
|
||||
|
2
tests-clar/resources/testrepo.git/FETCH_HEAD
Normal file
2
tests-clar/resources/testrepo.git/FETCH_HEAD
Normal file
@ -0,0 +1,2 @@
|
||||
a65fedf39aefe402d3bb6e24df4d4f5fe4547750 branch 'master' of git://example.com/git/testrepo.git
|
||||
258f0e2a959a364e40ed6603d5d44fbb24765b10 not-for-merge branch 'haacked' of git://example.com/git/testrepo.git
|
Loading…
Reference in New Issue
Block a user