summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Jeff King <peff@peff.net>2009-05-25 06:46:09 -0400
committerLibravatar Junio C Hamano <gitster@pobox.com>2009-05-25 11:34:02 -0700
commit3cd7388d57db4f4a29949e8de96493fb77059484 (patch)
treedfa546e4577ae9f13d6b2f7b18ddbb63b86e3a72
parentMerge branch 'maint' (diff)
downloadtgif-3cd7388d57db4f4a29949e8de96493fb77059484.tar.xz
convert bare readlink to strbuf_readlink
This particular readlink call never NUL-terminated its result, making it a potential source of bugs (though there is no bug now, as it currently always respects the length field). Let's just switch it to strbuf_readlink which is shorter and less error-prone. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--diff.c11
1 files changed, 4 insertions, 7 deletions
diff --git a/diff.c b/diff.c
index f06876be67..dcfbcb0215 100644
--- a/diff.c
+++ b/diff.c
@@ -2014,18 +2014,15 @@ static struct diff_tempfile *prepare_temp_file(const char *name,
die("stat(%s): %s", name, strerror(errno));
}
if (S_ISLNK(st.st_mode)) {
- int ret;
- char buf[PATH_MAX + 1]; /* ought to be SYMLINK_MAX */
- ret = readlink(name, buf, sizeof(buf));
- if (ret < 0)
+ struct strbuf sb = STRBUF_INIT;
+ if (strbuf_readlink(&sb, name, st.st_size) < 0)
die("readlink(%s)", name);
- if (ret == sizeof(buf))
- die("symlink too long: %s", name);
- prep_temp_blob(name, temp, buf, ret,
+ prep_temp_blob(name, temp, sb.buf, sb.len,
(one->sha1_valid ?
one->sha1 : null_sha1),
(one->sha1_valid ?
one->mode : S_IFLNK));
+ strbuf_release(&sb);
}
else {
/* we can borrow from the file in the work tree */