From: Linus Torvalds <torvalds@linux-foundation.org>
To: Junio C Hamano <gitster@pobox.com>,
Git Mailing List <git@vger.kernel.org>
Subject: [PATCH 5/5] Make 'prepare_temp_file()' ignore st_size for symlinks
Date: Wed, 17 Dec 2008 10:45:50 -0800 (PST) [thread overview]
Message-ID: <alpine.LFD.2.00.0812171044110.14014@localhost.localdomain> (raw)
In-Reply-To: <alpine.LFD.2.00.0812171043440.14014@localhost.localdomain>
From: Linus Torvalds <torvalds@linux-foundation.org>
Date: Wed, 17 Dec 2008 10:31:36 -0800
The code was already set up to not really need it, so this just massages
it a bit to remove the use entirely.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
---
There's a few raw 'readlink()' calls left, but they all seem to just have
a big buffer and rely on the return value of readlink() rather than look
too closely at st_size. But it would probably be good if somebody
double-checked it all.
Even so, this should all be better than what we used to have, though.
diff.c | 9 ++++-----
1 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/diff.c b/diff.c
index 4b2029c..f160c1a 100644
--- a/diff.c
+++ b/diff.c
@@ -1881,13 +1881,12 @@ static void prepare_temp_file(const char *name,
if (S_ISLNK(st.st_mode)) {
int ret;
char buf[PATH_MAX + 1]; /* ought to be SYMLINK_MAX */
- size_t sz = xsize_t(st.st_size);
- if (sizeof(buf) <= st.st_size)
- die("symlink too long: %s", name);
- ret = readlink(name, buf, sz);
+ ret = readlink(name, buf, sizeof(buf));
if (ret < 0)
die("readlink(%s)", name);
- prep_temp_blob(temp, buf, sz,
+ if (ret == sizeof(buf))
+ die("symlink too long: %s", name);
+ prep_temp_blob(temp, buf, ret,
(one->sha1_valid ?
one->sha1 : null_sha1),
(one->sha1_valid ?
--
1.6.1.rc3.3.gcc3e3
next prev parent reply other threads:[~2008-12-17 18:47 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-12-17 18:42 [PATCH 0/5] Be careful about lstat()-vs-readlink() Linus Torvalds
2008-12-17 18:42 ` [PATCH 1/5] Add generic 'strbuf_readlink()' helper function Linus Torvalds
2008-12-17 18:43 ` [PATCH 2/5] Make 'ce_compare_link()' use the new 'strbuf_readlink()' Linus Torvalds
2008-12-17 18:43 ` [PATCH 3/5] Make 'index_path()' use 'strbuf_readlink()' Linus Torvalds
2008-12-17 18:44 ` [PATCH 4/5] Make 'diff_populate_filespec()' use the new 'strbuf_readlink()' Linus Torvalds
2008-12-17 18:45 ` Linus Torvalds [this message]
2008-12-17 20:37 ` [PATCH 6/5] make_absolute_path(): check bounds when seeing an overlong symlink Junio C Hamano
2008-12-17 20:37 ` [PATCH 7/5] builtin-blame.c: use strbuf_readlink() Junio C Hamano
2008-12-17 20:37 ` [PATCH 8/5] combine-diff.c: " Junio C Hamano
2008-12-17 21:02 ` Linus Torvalds
2008-12-17 21:34 ` Junio C Hamano
2008-12-17 20:37 ` [PATCH 4/5] Make 'diff_populate_filespec()' use the new 'strbuf_readlink()' Junio C Hamano
2008-12-18 12:11 ` Mark Burton
2008-12-18 16:55 ` Linus Torvalds
2008-12-18 17:41 ` René Scharfe
2008-12-18 17:49 ` Linus Torvalds
2008-12-18 17:56 ` Olivier Galibert
2008-12-18 16:56 ` René Scharfe
2008-12-18 17:28 ` René Scharfe
2008-12-19 22:10 ` [PATCH] diff.c: fix pointer type warning René Scharfe
2008-12-19 23:09 ` Junio C Hamano
2008-12-17 20:37 ` [PATCH 3/5] Make 'index_path()' use 'strbuf_readlink()' Junio C Hamano
2008-12-17 21:26 ` [PATCH 1/5] Add generic 'strbuf_readlink()' helper function Jay Soffian
2008-12-17 21:44 ` Linus Torvalds
2008-12-23 10:05 ` [PATCH] strbuf_readlink semantics update Pierre Habouzit
2008-12-23 10:21 ` Pierre Habouzit
2008-12-23 18:16 ` Linus Torvalds
2008-12-24 10:11 ` Pierre Habouzit
2008-12-24 15:20 ` René Scharfe
2008-12-25 7:23 ` Junio C Hamano
2009-01-04 12:21 ` Pierre Habouzit
2009-01-06 20:41 ` [PATCH] strbuf: instate cleanup rule in case of non-memory errors René Scharfe
2009-01-07 21:19 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=alpine.LFD.2.00.0812171044110.14014@localhost.localdomain \
--to=torvalds@linux-foundation.org \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).