Re: [PATCH] Repalce strncmp by memcmp

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Steven Rostedt
Date: Monday, November 29, 2010 - 7:58 am

On Mon, 2010-11-29 at 05:09 +0300, Pavel Vasilyev wrote:

But these are not the same. strncmp() will stop when a or b hit a null.
I'm not sure if memcmp() must do so, It may for some reason check
anything within the memory of a+c-1 or b+c-1. What happens if a or b are
right at the end of a vmalloc page, and is just a single character and
null?

	x = vmalloc(32);
	strcpy(x, "some 31 byte string + null");

	call_func(x + 31);

in call_func we have:

	call_func(char *a) {

	strncmp(a, "this is some big string", 23);

With strncmp() when we hit a+1, it will stop comparing because a+1 is
null. With memcmp there's no such guarantee. We can then take a kernel
oops.

That will be a nice thing to try to debug.

Yes the above is contrived, but it demonstrates a possible problem with
this conversion.

-- Steve



--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH] Repalce strncmp by memcmp, Pavel Vasilyev, (Sun Nov 28, 7:09 pm)
Re: [PATCH] Repalce strncmp by memcmp, microcai, (Sun Nov 28, 7:21 pm)
Re: [PATCH] Repalce strncmp by memcmp, Ming Lei, (Sun Nov 28, 7:29 pm)
Re: [PATCH] Repalce strncmp by memcmp, Américo Wang, (Sun Nov 28, 8:10 pm)
Re: [PATCH] Repalce strncmp by memcmp, Pavel Vasilyev, (Sun Nov 28, 8:11 pm)
Re: [PATCH] Repalce strncmp by memcmp, Dmitry Torokhov, (Sun Nov 28, 9:13 pm)
Re: [PATCH] Repalce strncmp by memcmp, YOSHIFUJI Hideaki, (Sun Nov 28, 10:26 pm)
Re: [PATCH] Repalce strncmp by memcmp, Andi Kleen, (Mon Nov 29, 3:18 am)
Re: [PATCH] Repalce strncmp by memcmp, Pavel Vasilyev, (Mon Nov 29, 5:41 am)
Re: [PATCH] Repalce strncmp by memcmp, Steven Rostedt, (Mon Nov 29, 7:58 am)
Re: [PATCH] Repalce strncmp by memcmp, Pavel Vasilyev, (Mon Nov 29, 12:41 pm)
Re: [PATCH] Repalce strncmp by memcmp, Steven Rostedt, (Mon Nov 29, 3:18 pm)
Re: [PATCH] Repalce strncmp by memcmp, Steven Rostedt, (Mon Nov 29, 3:26 pm)
Re: [PATCH] Repalce strncmp by memcmp, Pavel Vasilyev, (Mon Nov 29, 3:49 pm)
Re: [PATCH] Repalce strncmp by memcmp, Ryan Mallon, (Mon Nov 29, 3:51 pm)
Re: [PATCH] Repalce strncmp by memcmp, Arnaud Lacombe, (Mon Nov 29, 4:32 pm)
Re: [PATCH] Repalce strncmp by memcmp, Américo Wang, (Tue Nov 30, 2:24 am)
Re: [PATCH] Repalce strncmp by memcmp, Bernd Petrovitsch, (Tue Nov 30, 3:27 am)
Re: [PATCH] Repalce strncmp by memcmp, Bernd Petrovitsch, (Tue Nov 30, 3:34 am)