git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Cc: GIT Mailing-list <git@vger.kernel.org>
Subject: Re: [PATCH 3/5] path.c: Use vsnpath() in the implementation of git_path()
Date: Tue, 04 Sep 2012 13:30:06 -0700	[thread overview]
Message-ID: <7vsjax8rap.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <50463A72.2000209@ramsay1.demon.co.uk> (Ramsay Jones's message of "Tue, 04 Sep 2012 18:29:22 +0100")

Ramsay Jones <ramsay@ramsay1.demon.co.uk> writes:

> The current implementation of git_path() is essentially the same as
> that of vsnpath(), with two minor differences. First, git_path()
> currently insists that the git directory path is no longer than
> PATH_MAX-100 characters in length. However, vsnpath() does not
> attempt this arbitrary 100 character reservation for the remaining
> path components. Second, vsnpath() uses the "is_dir_sep()" macro,
> rather than comparing directly to '/', to determine if the git_dir
> path component ends with a path separator.
> In order to benefit from the above improvements,...

In the longer term, I think this goes in the right direction, but
the loss of reservation, especially when we know git_path() is used
by some callers to get the base directory in $GIT_DIR that want to
append stuff after the returned directory path to form the final
pathname, is a bit worrysome.  It may be hiding a bug (lack of
proper limit check) on the callers' side.

> ... along with increased
> compatability with git_snpath() and git_pathdup(), we reimplement the
> git_path() function using vsnpath().
>
> Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
> ---
>  path.c | 15 +++------------
>  1 file changed, 3 insertions(+), 12 deletions(-)
>
> diff --git a/path.c b/path.c
> index 741ae77..cbbdf7d 100644
> --- a/path.c
> +++ b/path.c
> @@ -119,23 +119,14 @@ char *mkpath(const char *fmt, ...)
>  
>  char *git_path(const char *fmt, ...)
>  {
> -	const char *git_dir = get_git_dir();
>  	char *pathname = get_pathname();
>  	va_list args;
> -	unsigned len;
> +	char *ret;
>  
> -	len = strlen(git_dir);
> -	if (len > PATH_MAX-100)
> -		return bad_path;
> -	memcpy(pathname, git_dir, len);
> -	if (len && git_dir[len-1] != '/')
> -		pathname[len++] = '/';
>  	va_start(args, fmt);
> -	len += vsnprintf(pathname + len, PATH_MAX - len, fmt, args);
> +	ret = vsnpath(pathname, PATH_MAX, fmt, args);
>  	va_end(args);
> -	if (len >= PATH_MAX)
> -		return bad_path;
> -	return cleanup_path(pathname);
> +	return ret;
>  }
>  
>  void home_config_paths(char **global, char **xdg, char *file)

  reply	other threads:[~2012-09-04 20:30 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-04 17:29 [PATCH 3/5] path.c: Use vsnpath() in the implementation of git_path() Ramsay Jones
2012-09-04 20:30 ` Junio C Hamano [this message]
2012-09-07 19:19   ` Ramsay Jones

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=7vsjax8rap.fsf@alter.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=ramsay@ramsay1.demon.co.uk \
    /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).