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

Re: [PATCH] test-path-utils: use xsnprintf in favor of strcpy

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 8, 2016, 22:41 UTC
Message-ID
<xmqqh9hi6d00.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<20160208222155.GA17395@sigill.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 12 quoted lines
> This strcpy will never overflow because it's copying from
> baked-in test data. But we would prefer to avoid strcpy
> entirely, as it makes it harder to audit for real security
> bugs.
>
> Signed-off-by: Jeff King <peff@peff.net>
> ---
> Repost of <20160114202608.GA8806@sigill.intra.peff.net> from a few weeks
> ago (sorry, gmane is down so I can't generate a link). I think the
> original was never applied because the topic that introduced the strcpy
> (js/dirname-basename) predated xsnprintf, so there was some merging
> complexity. Now that topic is in master, so this can be applied there.

Thanks. This kind of considerate "holding it off for a few weeks" helps things a lot.

Show 17 quoted lines
>
>  test-path-utils.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/test-path-utils.c b/test-path-utils.c
> index c3adcd8..6232dfe 100644
> --- a/test-path-utils.c
> +++ b/test-path-utils.c
> @@ -56,7 +56,7 @@ static int test_function(struct test_data *data, char *(*func)(char *input),
>  		if (!data[i].from)
>  			to = func(NULL);
>  		else {
> -			strcpy(buffer, data[i].from);
> +			xsnprintf(buffer, sizeof(buffer), "%s", data[i].from);
>  			to = func(buffer);
>  		}
>  		if (!strcmp(to, data[i].to))
Previous: Junio C HamanoNext: Eric Wong
Message 4 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.