git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: Thomas Jarosch <thomas.jarosch@intra2net.com>, git@vger.kernel.org
Subject: [PATCH] convert bare readlink to strbuf_readlink
Date: Mon, 25 May 2009 06:46:09 -0400	[thread overview]
Message-ID: <20090525104609.GA26895@coredump.intra.peff.net> (raw)
In-Reply-To: <20090522153426.GA10390@coredump.intra.peff.net>

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>
---
This is a re-post with the missing strbuf_release added.

I am not overly married to this patch, so if you think it is code churn,
please just say so and drop it. I am just clearing out my "clean up and
submit" queue. :)

 diff.c |   11 ++++-------
 1 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/diff.c b/diff.c
index f06876b..dcfbcb0 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 */
-- 
1.6.3.1.250.g01b8b.dirty

  reply	other threads:[~2009-05-25 10:46 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-20  8:08 [PATCH] setup_revisions(): do not access outside argv Nguyễn Thái Ngọc Duy
2009-05-20  8:15 ` Johannes Sixt
2009-05-20  8:23   ` Nguyen Thai Ngoc Duy
2009-05-21  1:58     ` Junio C Hamano
2009-05-21  2:38       ` Miles Bader
2009-05-21  2:41       ` Nguyen Thai Ngoc Duy
2009-05-21  4:18       ` Jeff King
2009-05-21 18:02         ` Thomas Jarosch
2009-05-22  7:56           ` Jeff King
2009-05-22  8:02             ` Jeff King
2009-05-22 14:23               ` Thomas Jarosch
2009-05-22 15:33               ` Brandon Casey
2009-05-22 15:34                 ` Jeff King
2009-05-25 10:46                   ` Jeff King [this message]
2009-05-25 22:23                     ` [PATCH] convert bare readlink to strbuf_readlink Junio C Hamano
     [not found]               ` <20090602195605.6117@nanako3.lavabit.com>
2009-06-02 13:57                 ` [PATCH] setup_revisions(): do not access outside argv Jeff King

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=20090525104609.GA26895@coredump.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=thomas.jarosch@intra2net.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).