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 <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Michael Haggerty committed Sep 15, 2011 at 23:10 UTC f989fea0e0b47873de62a355f4766f03a88fb01b
1 file changed +2 -1
refs.c
+2 -1
@@ -593,7 +593,8 @@ const char *resolve_ref(const char *ref, unsigned char *sha1, int reading, int *
593 if (flag)
594 *flag |= REF_ISSYMREF;
595 }
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]))) {
598 warning("reference in %s is formatted incorrectly", path);
599 return NULL;
600 }