Skip to content

Commit

Permalink
Make 'diff_populate_filespec()' use the new 'strbuf_readlink()'
Browse files Browse the repository at this point in the history
This makes all tests pass on a system where 'lstat()' has been hacked to
return bogus data in st_size for symlinks.

Of course, the test coverage isn't complete, but it's a good baseline.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Linus Torvalds authored and Junio C Hamano committed Dec 17, 2008
1 parent b760d3a commit cf219d8
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -1773,19 +1773,17 @@ int diff_populate_filespec(struct diff_filespec *s, int size_only)
s->size = xsize_t(st.st_size);
if (!s->size)
goto empty;
if (size_only)
return 0;
if (S_ISLNK(st.st_mode)) {
int ret;
s->data = xmalloc(s->size);
s->should_free = 1;
ret = readlink(s->path, s->data, s->size);
if (ret < 0) {
free(s->data);
struct strbuf sb = STRBUF_INIT;

if (strbuf_readlink(&sb, s->path, s->size))
goto err_empty;
}
s->data = strbuf_detach(&sb, &s->size);
s->should_free = 1;
return 0;
}
if (size_only)
return 0;
fd = open(s->path, O_RDONLY);
if (fd < 0)
goto err_empty;
Expand Down

0 comments on commit cf219d8

Please sign in to comment.