Skip to content

Commit

Permalink
resolve_ref(): explicitly fail if a symlink is not readable
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Michael Haggerty authored and Junio C Hamano committed Oct 5, 2011
1 parent a40e6fb commit 7bb2bf8
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions refs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 7bb2bf8

Please sign in to comment.