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

Re: [PATCH 1/3] path.c: fix uninitialized memory access

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Oct 3, 2017, 23:37 UTC
Message-ID
<20171003233706.GH19555@aiede.mtv.corp.google.com>
In-Reply-To
<20171003233040.2ws6kny3e4kypfub@sigill.intra.peff.net>
Jeff King wrote:
> On Tue, Oct 03, 2017 at 03:45:01PM -0700, Jonathan Nieder wrote:
Show 13 quoted lines
>> In other words, an alternative fix would be
>> 
>> 	if (*path == '.' && path[1] == '/') {
>> 		...
>> 	}
>> 
>> which would not require passing in 'len' or switching to index-based
>> arithmetic.  I think I prefer it.  What do you think?
>
> Yes, I think that approach is much nicer. I think you could even use
> skip_prefix. Unfortunately you have to play a few games with const-ness,
> but I think the resulting signature for cleanup_path() is an
> improvement:
Ooh!

For what it's worth, if you add a commit message with Thomas's Reported-by then this lgtm.

Thanks, Jonathan

Show 36 quoted lines
> diff --git a/path.c b/path.c
> index 00ec04e7a5..2e09a7bce0 100644
> --- a/path.c
> +++ b/path.c
> @@ -34,11 +34,10 @@ static struct strbuf *get_pathname(void)
>  	return sb;
>  }
>  
> -static char *cleanup_path(char *path)
> +static const char *cleanup_path(const char *path)
>  {
>  	/* Clean it up */
> -	if (!memcmp(path, "./", 2)) {
> -		path += 2;
> +	if (skip_prefix(path, "./", &path)) {
>  		while (*path == '/')
>  			path++;
>  	}
> @@ -47,7 +46,7 @@ static char *cleanup_path(char *path)
>  
>  static void strbuf_cleanup_path(struct strbuf *sb)
>  {
> -	char *path = cleanup_path(sb->buf);
> +	const char *path = cleanup_path(sb->buf);
>  	if (path > sb->buf)
>  		strbuf_remove(sb, 0, path - sb->buf);
>  }
> @@ -64,7 +63,7 @@ char *mksnpath(char *buf, size_t n, const char *fmt, ...)
>  		strlcpy(buf, bad_path, n);
>  		return buf;
>  	}
> -	return cleanup_path(buf);
> +	return (char *)cleanup_path(buf);
>  }
>  
>  static int dir_prefix(const char *buf, const char *dir)
Previous: Jeff KingNext: Junio C Hamano
Message 5 of 30 in “fixes for running the test suite with --valgrind”
  1. 0/3 fixes for running the test suite with --valgrindThomas Gummerer, Oct 3, 2017
  2. 1/3 path.c: fix uninitialized memory accessThomas Gummerer, Oct 3, 2017
  3. Jonathan NiederOct 3, 2017
  4. Jeff KingOct 3, 2017
  5. Jonathan NiederOct 3, 2017
  6. Junio C HamanoOct 4, 2017
  7. Jeff KingOct 4, 2017
  8. Thomas GummererOct 4, 2017
  9. Jonathan NiederOct 4, 2017
  10. 2/3 http-push: fix construction of hex value from pathThomas Gummerer, Oct 3, 2017
  11. Jonathan NiederOct 3, 2017
  12. Jeff KingOct 3, 2017
  13. Junio C HamanoOct 4, 2017
  14. Junio C HamanoOct 4, 2017
  15. Jeff KingOct 4, 2017
  16. Junio C HamanoOct 4, 2017
  17. 3/3 sub-process: allocate argv on the heapThomas Gummerer, Oct 3, 2017
  18. Johannes SixtOct 3, 2017
  19. Junio C HamanoOct 4, 2017
  20. Jeff KingOct 4, 2017
  21. Johannes SixtOct 4, 2017
  22. Thomas GummererOct 4, 2017
  23. Stefan BellerOct 3, 2017
  24. Jeff KingOct 3, 2017
  25. Jonathan NiederOct 3, 2017
  26. Jeff KingOct 3, 2017
  27. playing with MSan, was Re: [PATCH 0/3] fixes for running the test suite with --valgrindJeff King, Oct 4, 2017
  28. Thomas GummererOct 4, 2017
  29. lstat-ing delayed-filter output, was Re: playing with MSanJeff King, Oct 5, 2017
  30. Lars SchneiderOct 5, 2017

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.