All of lore.kernel.org
 help / color / mirror / Atom feed
From: "René Scharfe" <rene.scharfe@lsrfire.ath.cx>
To: Erik Faye-Lund <kusmabite@gmail.com>
Cc: git@vger.kernel.org, peff@peff.net, j6t@kdbg.org, gitster@pobox.com
Subject: Re: [PATCH v3 3/4] enter_repo: do not modify input
Date: Fri, 30 Sep 2011 21:00:00 +0200	[thread overview]
Message-ID: <4E8611B0.7020709@lsrfire.ath.cx> (raw)
In-Reply-To: <1317329963-6656-4-git-send-email-kusmabite@gmail.com>

Am 29.09.2011 22:59, schrieb Erik Faye-Lund:
> diff --git a/path.c b/path.c
> index 6f3f5d5..f7dfd0b 100644
> --- a/path.c
> +++ b/path.c
> @@ -283,7 +283,7 @@ return_null:
>   * links.  User relative paths are also returned as they are given,
>   * except DWIM suffixing.
>   */
> -char *enter_repo(char *path, int strict)
> +const char *enter_repo(const char *path, int strict)
>  {
>  	static char used_path[PATH_MAX];
>  	static char validated_path[PATH_MAX];
> @@ -297,14 +297,15 @@ char *enter_repo(char *path, int strict)
>  		};
>  		int len = strlen(path);
>  		int i;
> -		while ((1 < len) && (path[len-1] == '/')) {
> -			path[len-1] = 0;
> +		while ((1 < len) && (path[len-1] == '/'))
>  			len--;
> -		}
> +
>  		if (PATH_MAX <= len)
>  			return NULL;
> -		if (path[0] == '~') {
> -			char *newpath = expand_user_path(path);
> +		strncpy(used_path, path, len);
> +
> +		if (used_path[0] == '~') {
> +			char *newpath = expand_user_path(used_path);
>  			if (!newpath || (PATH_MAX - 10 < strlen(newpath))) {
>  				free(newpath);
>  				return NULL;
> @@ -316,24 +317,21 @@ char *enter_repo(char *path, int strict)
>  			 * anyway.
>  			 */
>  			strcpy(used_path, newpath); free(newpath);
> -			strcpy(validated_path, path);
> -			path = used_path;
> +			strcpy(validated_path, used_path);
>  		}
>  		else if (PATH_MAX - 10 < len)
>  			return NULL;
> -		else {
> -			path = strcpy(used_path, path);
> -			strcpy(validated_path, path);
> -		}
> -		len = strlen(path);
> +		else
> +			strcpy(validated_path, used_path);
> +		len = strlen(used_path);
>  		for (i = 0; suffix[i]; i++) {
> -			strcpy(path + len, suffix[i]);
> -			if (!access(path, F_OK)) {
> +			strcpy(used_path + len, suffix[i]);
> +			if (!access(used_path, F_OK)) {
>  				strcat(validated_path, suffix[i]);
>  				break;
>  			}
>  		}
> -		if (!suffix[i] || chdir(path))
> +		if (!suffix[i] || chdir(used_path))
>  			return NULL;
>  		path = validated_path;
>  	}

The use of strcpy and strncpy makes me nervous, but I can't spot a bug
currently and strcpy and even strcat calls had been already in there
before your patch.

René

  reply	other threads:[~2011-09-30 19:00 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-29 20:59 [PATCH v3 0/4] port upload-archive to Windows Erik Faye-Lund
2011-09-29 20:59 ` [PATCH v3 1/4] compat/win32/sys/poll.c: upgrade from upstream Erik Faye-Lund
2011-09-30 19:00   ` René Scharfe
2011-09-29 20:59 ` [PATCH v3 2/4] mingw: fix compilation of poll-emulation Erik Faye-Lund
2011-09-29 20:59 ` [PATCH v3 3/4] enter_repo: do not modify input Erik Faye-Lund
2011-09-30 19:00   ` René Scharfe [this message]
2011-10-04 17:55   ` Phil Hord
2011-10-04 18:00     ` Phil Hord
2011-10-06 13:06     ` Erik Faye-Lund
2011-09-29 20:59 ` [PATCH v3 4/4] upload-archive: use start_command instead of fork Erik Faye-Lund
2011-10-03 18:39   ` Junio C Hamano
2011-10-03 18:48     ` Erik Faye-Lund
2011-10-03 19:31       ` Junio C Hamano
2011-09-29 21:01 ` [PATCH v3 0/4] port upload-archive to Windows Erik Faye-Lund
2011-09-30 10:46 ` 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=4E8611B0.7020709@lsrfire.ath.cx \
    --to=rene.scharfe@lsrfire.ath.cx \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=j6t@kdbg.org \
    --cc=kusmabite@gmail.com \
    --cc=peff@peff.net \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.