resolve_ref(): explicitly fail if a symlink is not readable

Previously the failure came later, after a few steps in which the length was treated like the actual length of a string. Even though the old code gave the same answers, it was somewhat misleading. 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 7bb2bf8e5cc47f7731c9c012ecc943b14f99ee5a
1 file changed +2
refs.c
+2
@@ -518,6 +518,8 @@ const char *resolve_ref(const char *ref, unsigned char *sha1, int reading, int *
518 /* Follow "normalized" - ie "refs/.." symlinks by hand */
519 if (S_ISLNK(st.st_mode)) {
520 len = readlink(path, buffer, sizeof(buffer)-1);
521 + if (len < 0)
522 + return NULL;
523 if (len >= 5 && !memcmp("refs/", buffer, 5)) {
524 buffer[len] = 0;
525 strcpy(ref_buffer, buffer);