From: David Turner <dturner@twopensource.com>
To: Ramsay Jones <ramsay@ramsayjones.plus.com>,
Nguyen Thai Ngoc Duy <pclouds@gmail.com>
Cc: Jeff King <peff@peff.net>, Junio C Hamano <gitster@pobox.com>,
GIT Mailing-list <git@vger.kernel.org>
Subject: Re: [PATCH 3/3] index-helper: take extra care with readlink
Date: Mon, 11 Apr 2016 17:53:05 -0400 [thread overview]
Message-ID: <1460411585.5540.21.camel@twopensource.com> (raw)
In-Reply-To: <570ADBCB.4040503@ramsayjones.plus.com>
On Mon, 2016-04-11 at 00:03 +0100, Ramsay Jones wrote:
> It took me a few minutes to convince myself that, if index-helper is
> the only writer for the symlink, that the call to readlink would
> result in a properly NULL terminated string. This relies on the
> initialization of the address variable setting each byte of the
> 'struct sockaddr_un' to zero and the contents of the symlink being
> no more than 'sizeof(address.sun_path) - 1' bytes long.
>
> In order to make the call easier to reason about, introduce a wrapper
> function, read_link(), which copes with overlong symlinks and ensures
> correct NULL termination.
>
> Signed-off-by: Ramsay Jones <ramsay@ramsayjones.plus.com>
> ---
> read-cache.c | 13 ++++++++++++-
> 1 file changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/read-cache.c b/read-cache.c
> index c7053d8..39330a1 100644
> --- a/read-cache.c
> +++ b/read-cache.c
> @@ -1722,12 +1722,23 @@ static void post_read_index_from(struct
> index_state *istate)
> tweak_untracked_cache(istate);
> }
>
> +static int read_link(const char *path, char *buf, size_t bufsize)
> +{
> + int len;
> +
> + len = readlink(path, buf, bufsize);
> + if (len < 0 || len >= bufsize)
> + return -1;
> + buf[len] = '\0';
> + return 0;
> +}
> +
> int connect_to_index_helper(void)
> {
> struct sockaddr_un address = {0};
> int fd;
>
> - if (readlink(git_path("index-helper.path"),
> address.sun_path,
> + if (read_link(git_path("index-helper.path"),
> address.sun_path,
> sizeof(address.sun_path)) < 0)
> return -1;
>
Will squash.
prev parent reply other threads:[~2016-04-11 21:53 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-10 23:03 [PATCH 3/3] index-helper: take extra care with readlink Ramsay Jones
2016-04-11 4:17 ` Torsten Bögershausen
2016-04-11 21:53 ` David Turner [this message]
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=1460411585.5540.21.camel@twopensource.com \
--to=dturner@twopensource.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=pclouds@gmail.com \
--cc=peff@peff.net \
--cc=ramsay@ramsayjones.plus.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).