git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] test-path-utils: use xsnprintf in favor of strcpy
@ 2016-01-14 20:26 Jeff King
  2016-01-15  6:45 ` Johannes Schindelin
  0 siblings, 1 reply; 9+ messages in thread
From: Jeff King @ 2016-01-14 20:26 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Johannes Schindelin, git

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>
---
I admit that an audit could probably just avoid looking at test-* in the
first place, but not all do (coverity complained about this one, for
example).

This sort-of applies on top of js/dirname-basename, which is in next.
Textually, it's fine, but that topic is based on v2.6.5, and xsnprintf
was only added in the v2.7.0 cycle. The simplest thing is probably to
wait for it to graduate to master, and then apply there as a new topic
(if we do v2.6.6, it's OK for it not to have this patch).

I can hold and resend in a week or two if that's easier.

 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 4ab68ac..b9ece10 100644
--- a/test-path-utils.c
+++ b/test-path-utils.c
@@ -55,7 +55,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)) {
-- 
2.7.0.244.g0701a9d

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] test-path-utils: use xsnprintf in favor of strcpy
  2016-01-14 20:26 [PATCH] test-path-utils: use xsnprintf in favor of strcpy Jeff King
@ 2016-01-15  6:45 ` Johannes Schindelin
  2016-01-15 18:30   ` Jeff King
  0 siblings, 1 reply; 9+ messages in thread
From: Johannes Schindelin @ 2016-01-15  6:45 UTC (permalink / raw)
  To: Jeff King; +Cc: Junio C Hamano, git

Hi Peff,

On Thu, 14 Jan 2016, Jeff King wrote:

> 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.

Thanks.

> This sort-of applies on top of js/dirname-basename, which is in next.
> Textually, it's fine, but that topic is based on v2.6.5, and xsnprintf
> was only added in the v2.7.0 cycle. The simplest thing is probably to
> wait for it to graduate to master, and then apply there as a new topic
> (if we do v2.6.6, it's OK for it not to have this patch).
> 
> I can hold and resend in a week or two if that's easier.

If you have a patch to make dirname/basename safer based on xsnprintf, I
would like to have that as soon as possible (next was rewound to 2.7.0,
no?)...

Thanks!
Dscho

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] test-path-utils: use xsnprintf in favor of strcpy
  2016-01-15  6:45 ` Johannes Schindelin
@ 2016-01-15 18:30   ` Jeff King
  2016-01-19 11:05     ` Johannes Schindelin
  0 siblings, 1 reply; 9+ messages in thread
From: Jeff King @ 2016-01-15 18:30 UTC (permalink / raw)
  To: Johannes Schindelin; +Cc: Junio C Hamano, git

On Fri, Jan 15, 2016 at 07:45:16AM +0100, Johannes Schindelin wrote:

> > This sort-of applies on top of js/dirname-basename, which is in next.
> > Textually, it's fine, but that topic is based on v2.6.5, and xsnprintf
> > was only added in the v2.7.0 cycle. The simplest thing is probably to
> > wait for it to graduate to master, and then apply there as a new topic
> > (if we do v2.6.6, it's OK for it not to have this patch).
> > 
> > I can hold and resend in a week or two if that's easier.
> 
> If you have a patch to make dirname/basename safer based on xsnprintf, I
> would like to have that as soon as possible (next was rewound to 2.7.0,
> no?)...

I'm not sure what you mean. `dirname/basename` themselves don't have any
problems. It's only the `strcpy` in the test program that I wanted to
fix.

If Junio wants to rebase js/dirname-basename on a more recent tip (say,
current "master") as part of the rewind, this could be applied directly
(or just squashed in).

-Peff

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] test-path-utils: use xsnprintf in favor of strcpy
  2016-01-15 18:30   ` Jeff King
@ 2016-01-19 11:05     ` Johannes Schindelin
  0 siblings, 0 replies; 9+ messages in thread
From: Johannes Schindelin @ 2016-01-19 11:05 UTC (permalink / raw)
  To: Jeff King; +Cc: Junio C Hamano, git

Hi Peff,

On Fri, 15 Jan 2016, Jeff King wrote:

> On Fri, Jan 15, 2016 at 07:45:16AM +0100, Johannes Schindelin wrote:
> 
> > > This sort-of applies on top of js/dirname-basename, which is in next.
> > > Textually, it's fine, but that topic is based on v2.6.5, and xsnprintf
> > > was only added in the v2.7.0 cycle. The simplest thing is probably to
> > > wait for it to graduate to master, and then apply there as a new topic
> > > (if we do v2.6.6, it's OK for it not to have this patch).
> > > 
> > > I can hold and resend in a week or two if that's easier.
> > 
> > If you have a patch to make dirname/basename safer based on xsnprintf, I
> > would like to have that as soon as possible (next was rewound to 2.7.0,
> > no?)...
> 
> I'm not sure what you mean. `dirname/basename` themselves don't have any
> problems. It's only the `strcpy` in the test program that I wanted to
> fix.
> 
> If Junio wants to rebase js/dirname-basename on a more recent tip (say,
> current "master") as part of the rewind, this could be applied directly
> (or just squashed in).

My bad... I misunderstood which code was affected.

Sorry for the noise,
Dscho

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH] test-path-utils: use xsnprintf in favor of strcpy
@ 2016-02-08 22:21 Jeff King
  2016-02-08 22:41 ` Junio C Hamano
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Jeff King @ 2016-02-08 22:21 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Johannes Schindelin, git

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.

 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))
-- 
2.7.1.526.gd04f550

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] test-path-utils: use xsnprintf in favor of strcpy
  2016-02-08 22:21 Jeff King
@ 2016-02-08 22:41 ` Junio C Hamano
  2016-02-08 23:07 ` Eric Wong
  2016-02-09 10:13 ` Johannes Schindelin
  2 siblings, 0 replies; 9+ messages in thread
From: Junio C Hamano @ 2016-02-08 22:41 UTC (permalink / raw)
  To: Jeff King; +Cc: Johannes Schindelin, git

Jeff King <peff@peff.net> writes:

> 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.

>
>  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))

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] test-path-utils: use xsnprintf in favor of strcpy
  2016-02-08 22:21 Jeff King
  2016-02-08 22:41 ` Junio C Hamano
@ 2016-02-08 23:07 ` Eric Wong
  2016-02-08 23:13   ` Jeff King
  2016-02-09 10:13 ` Johannes Schindelin
  2 siblings, 1 reply; 9+ messages in thread
From: Eric Wong @ 2016-02-08 23:07 UTC (permalink / raw)
  To: Jeff King; +Cc: Junio C Hamano, Johannes Schindelin, git

Jeff King <peff@peff.net> wrote:
> 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 prefer we use links derived from Message-IDs anyways.  This
prevents reliance on gmane article numbers being a central point
of failure:

http://marc.info/?i=$MESSAGE_ID
http://mid.gmane.org/$MESSAGE_ID
http://mid.mail-archive.com/$MESSAGE_ID

But the MESSAGE_ID above seems missing from mail-archive.com, in this case.

Maybe there's more lookup-by-Message-ID services out there...

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] test-path-utils: use xsnprintf in favor of strcpy
  2016-02-08 23:07 ` Eric Wong
@ 2016-02-08 23:13   ` Jeff King
  0 siblings, 0 replies; 9+ messages in thread
From: Jeff King @ 2016-02-08 23:13 UTC (permalink / raw)
  To: Eric Wong; +Cc: Junio C Hamano, Johannes Schindelin, git

On Mon, Feb 08, 2016 at 11:07:26PM +0000, Eric Wong wrote:

> Jeff King <peff@peff.net> wrote:
> > 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 prefer we use links derived from Message-IDs anyways.  This
> prevents reliance on gmane article numbers being a central point
> of failure:
> 
> http://marc.info/?i=$MESSAGE_ID
> http://mid.gmane.org/$MESSAGE_ID
> http://mid.mail-archive.com/$MESSAGE_ID

I actually do, too. I keep a local archive of the whole list, and I have
a script that hits gmane to convert their article ids into message-ids.
When gmane is down I can still use my archive, but I can't resolve
anybody's article mentions. :)

I mostly use gmane links because people are used to them, though (I also
don't think there's a way using message-ids to point to a whole thread
with an article highlighted, though of course readers can get their by
clicking through).

> But the MESSAGE_ID above seems missing from mail-archive.com, in this case.

It seems to have a giant hole in git@vger messages between 2016-01-07
and 2016-01-20, which covers the referenced message (which was on the
14th).

-Peff

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] test-path-utils: use xsnprintf in favor of strcpy
  2016-02-08 22:21 Jeff King
  2016-02-08 22:41 ` Junio C Hamano
  2016-02-08 23:07 ` Eric Wong
@ 2016-02-09 10:13 ` Johannes Schindelin
  2 siblings, 0 replies; 9+ messages in thread
From: Johannes Schindelin @ 2016-02-09 10:13 UTC (permalink / raw)
  To: Jeff King; +Cc: Junio C Hamano, git

Hi Peff,

On Mon, 8 Feb 2016, Jeff King wrote:

> 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>

ACK, of course.

Thanks!
Dscho

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2016-02-09 10:13 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-01-14 20:26 [PATCH] test-path-utils: use xsnprintf in favor of strcpy Jeff King
2016-01-15  6:45 ` Johannes Schindelin
2016-01-15 18:30   ` Jeff King
2016-01-19 11:05     ` Johannes Schindelin
  -- strict thread matches above, loose matches on Subject: below --
2016-02-08 22:21 Jeff King
2016-02-08 22:41 ` Junio C Hamano
2016-02-08 23:07 ` Eric Wong
2016-02-08 23:13   ` Jeff King
2016-02-09 10:13 ` Johannes Schindelin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).