threads / patch / 41194

patchtest-path-utils: use xsnprintf in favor of strcpy

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

## tl;dr

4 messages between Jan 14, 2016 and Jan 19, 2016. Diffs are folded; open one to read it.

replies: 3people: 2as markdown or json

Jeff King· Jan 14, 2016, 20:26 UTC · lore

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(-)
Show changes to test-path-utils.c +1 −1
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
Johannes Schindelin· Jan 15, 2016, 06:45 UTC · re: Jeff King · lore

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

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.
Show 7 quoted lines
> 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

Jeff King· Jan 15, 2016, 18:30 UTC · re: Johannes Schindelin · lore

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

On Fri, Jan 15, 2016 at 07:45:16AM +0100, Johannes Schindelin wrote:
Show 11 quoted lines
> > 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
Johannes Schindelin· Jan 19, 2016, 11:05 UTC · re: Jeff King · lore

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

Hi Peff,
On Fri, 15 Jan 2016, Jeff King wrote:
Show 21 quoted lines
> 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

← back to recent threads