git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v3 3/4] enter_repo: do not modify input

From
René Scharfe <rene.scharfe@lsrfire.ath.cx>
Date
Sep 30, 2011, 19:00 UTC
Message-ID
<4E8611B0.7020709@lsrfire.ath.cx>
In-Reply-To
<1317329963-6656-4-git-send-email-kusmabite@gmail.com>
Am 29.09.2011 22:59, schrieb Erik Faye-Lund:
Show 66 quoted lines
> 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é
Previous: Erik Faye-LundNext: Phil Hord
Message 6 of 15 in “port upload-archive to Windows”
  1. 0/4 port upload-archive to WindowsErik Faye-Lund, Sep 29, 2011
  2. 1/4 compat/win32/sys/poll.c: upgrade from upstreamErik Faye-Lund, Sep 29, 2011
  3. René ScharfeSep 30, 2011
  4. 2/4 mingw: fix compilation of poll-emulationErik Faye-Lund, Sep 29, 2011
  5. 3/4 enter_repo: do not modify inputErik Faye-Lund, Sep 29, 2011
  6. René ScharfeSep 30, 2011
  7. Phil HordOct 4, 2011
  8. Phil HordOct 4, 2011
  9. Erik Faye-LundOct 6, 2011
  10. 4/4 upload-archive: use start_command instead of forkErik Faye-Lund, Sep 29, 2011
  11. Junio C HamanoOct 3, 2011
  12. Erik Faye-LundOct 3, 2011
  13. Junio C HamanoOct 3, 2011
  14. Erik Faye-LundSep 29, 2011
  15. Jeff KingSep 30, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.