Code

resolve_ref(): explicitly fail if a symlink is not readable
authorMichael Haggerty <mhagger@alum.mit.edu>
Thu, 15 Sep 2011 21:10:31 +0000 (23:10 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 5 Oct 2011 20:45:30 +0000 (13:45 -0700)
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>
refs.c

diff --git a/refs.c b/refs.c
index d2aac24a366f946ea5a256a7bc47f10d36f98a88..c51fd45f99ef3a6d5fdb56b6bd5ba9a554f2e8f8 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -518,6 +518,8 @@ const char *resolve_ref(const char *ref, unsigned char *sha1, int reading, int *
                /* Follow "normalized" - ie "refs/.." symlinks by hand */
                if (S_ISLNK(st.st_mode)) {
                        len = readlink(path, buffer, sizeof(buffer)-1);
+                       if (len < 0)
+                               return NULL;
                        if (len >= 5 && !memcmp("refs/", buffer, 5)) {
                                buffer[len] = 0;
                                strcpy(ref_buffer, buffer);