Skip to content

Commit f989fea

Browse files
mhaggergitster
authored andcommitted
resolve_ref(): also treat a too-long SHA1 as invalid
If the SHA1 in a reference file is not terminated by a space or end-of-file, consider it malformed and emit a warning. Signed-off-by: Michael Haggerty <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 629cd3a commit f989fea

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

refs.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,8 @@ const char *resolve_ref(const char *ref, unsigned char *sha1, int reading, int *
593593
if (flag)
594594
*flag |= REF_ISSYMREF;
595595
}
596-
if (get_sha1_hex(buffer, sha1)) {
596+
/* Please note that FETCH_HEAD has a second line containing other data. */
597+
if (get_sha1_hex(buffer, sha1) || (buffer[40] != '\0' && !isspace(buffer[40]))) {
597598
warning("reference in %s is formatted incorrectly", path);
598599
return NULL;
599600
}

0 commit comments

Comments
 (0)