Skip to content

Commit 7bb2bf8

Browse files
mhaggergitster
authored andcommitted
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>
1 parent a40e6fb commit 7bb2bf8

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

refs.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,8 @@ const char *resolve_ref(const char *ref, unsigned char *sha1, int reading, int *
518518
/* Follow "normalized" - ie "refs/.." symlinks by hand */
519519
if (S_ISLNK(st.st_mode)) {
520520
len = readlink(path, buffer, sizeof(buffer)-1);
521+
if (len < 0)
522+
return NULL;
521523
if (len >= 5 && !memcmp("refs/", buffer, 5)) {
522524
buffer[len] = 0;
523525
strcpy(ref_buffer, buffer);

0 commit comments

Comments
 (0)