diff options
author | Carlos Martín Nieto <cmn@dwim.me> | 2012-10-15 13:51:25 +0200 |
---|---|---|
committer | Carlos Martín Nieto <cmn@dwim.me> | 2012-10-15 14:00:19 +0200 |
commit | 47f44b6ee424921cf5aef064fe6ecf768c6ec5ea (patch) | |
tree | baf5cffab7b8dc1d85679a931b952809692ac818 /src/refs.c | |
parent | 9d9288f417968a7fd583786a749c4f7dfa258f89 (diff) | |
download | libgit2-47f44b6ee424921cf5aef064fe6ecf768c6ec5ea.tar.gz |
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.
Diffstat (limited to 'src/refs.c')
-rw-r--r-- | src/refs.c | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/src/refs.c b/src/refs.c index 1d73b2677..9e2311b07 100644 --- a/src/refs.c +++ b/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; } |