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

Re: [PATCH] rerere: replace strcpy with xsnprintf

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 8, 2016, 23:07 UTC
Message-ID
<xmqqd1s66bt8.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<20160208222501.GA21671@sigill.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 13 quoted lines
> This shouldn't overflow, as we are copying a sha1 hex into a
> 41-byte buffer. But it does not hurt to use a bound-checking
> function, which protects us and makes auditing for overflows
> easier.
>
> Signed-off-by: Jeff King <peff@peff.net>
> ---
> These strcpy calls go away in jc/rerere-multi, so I was holding onto
> this to see if that graduated. But since that is stalled, I figured it
> cannot hurt to post (and the conflict resolution is obviously trivial).
>
> With this and the previous patch, it makes our code base strcpy free.
> Yay.
Thanks.  I think jc/rerere-multi can be rerolled on top of this.
Show 25 quoted lines
>
>  rerere.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/rerere.c b/rerere.c
> index 403c700..587b7e2 100644
> --- a/rerere.c
> +++ b/rerere.c
> @@ -48,7 +48,7 @@ static int has_rerere_resolution(const struct rerere_id *id)
>  static struct rerere_id *new_rerere_id_hex(char *hex)
>  {
>  	struct rerere_id *id = xmalloc(sizeof(*id));
> -	strcpy(id->hex, hex);
> +	xsnprintf(id->hex, sizeof(id->hex), "%s", hex);
>  	return id;
>  }
>  
> @@ -904,7 +904,7 @@ int rerere_forget(struct pathspec *pathspec)
>  static struct rerere_id *dirname_to_id(const char *name)
>  {
>  	static struct rerere_id id;
> -	strcpy(id.hex, name);
> +	xsnprintf(id.hex, sizeof(id.hex), "%s", name);
>  	return &id;
>  }
Previous: Jeff KingNext: Junio C Hamano
Message 3 of 7 in “test-path-utils: use xsnprintf in favor of strcpy”
  1. test-path-utils: use xsnprintf in favor of strcpyJeff King, Feb 8, 2016
  2. rerere: replace strcpy with xsnprintfJeff King, Feb 8, 2016
  3. Junio C HamanoFeb 8, 2016
  4. Junio C HamanoFeb 8, 2016
  5. Eric WongFeb 8, 2016
  6. Jeff KingFeb 8, 2016
  7. Johannes SchindelinFeb 9, 2016

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.