summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 9619ff1)
raw | patch | inline | side by side (parent: 9619ff1)
author | Jeff King <peff@peff.net> | |
Mon, 25 May 2009 10:46:09 +0000 (06:46 -0400) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Mon, 25 May 2009 18:34:02 +0000 (11:34 -0700) |
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>
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>
diff.c | patch | blob | history |
index f06876be67245ab559b57168553cfd71b9d23feb..dcfbcb0215766efefa786b18d793c4bf96740b8c 100644 (file)
--- a/diff.c
+++ b/diff.c
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 */