Re: [PATCH] fix buffer overflow in udev_util_replace_whitespace()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 9/5/09, Florian Zumbiehl <florz@xxxxxxxx> wrote:
> Hi,
>
>> > diff --git a/libudev/libudev-util.c b/libudev/libudev-util.c
>> > index 9a141db..a2aef84 100644
>> > --- a/libudev/libudev-util.c
>> > +++ b/libudev/libudev-util.c
>> > @@ -355,7 +355,7 @@ int udev_util_replace_whitespace(const char *str,
>> >  char *to, size_t len) size_t i, j;
>> >
>> >  	/* strip trailing whitespace */
>> > -	len = strnlen(str, len);
>> > +	len = strnlen(str, len-1);
>> >  	while (len && isspace(str[len-1]))
>> >  		len--;
>> >
>> wrong.
>
> Because?

before

strnlen("a", 2) = 1
isspace("a"[1-1]) = 0
-> final value of len = 1.
"a" fits in a 2 byte buffer.

after

strnlen("a", 2-1) = 0

-> "a" will be truncated to "" even though it would fit in a two-byte buffer

>> Please try to understand what this loop does.
>
> And then?
>
> Florian
> --
> To unsubscribe from this list: send the line "unsubscribe linux-hotplug" in
> the body of a message to majordomo@xxxxxxxxxxxxxxx
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>
--
To unsubscribe from this list: send the line "unsubscribe linux-hotplug" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel]     [Linux DVB]     [Asterisk Internet PBX]     [DCCP]     [Netdev]     [X.org]     [Util Linux NG]     [Fedora Women]     [ALSA Devel]     [Linux USB]

  Powered by Linux