lkml.org 
[lkml]   [2015]   [Oct]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] string: Improve the generic strlcpy() implementation

* Ingo Molnar <mingo@kernel.org> wrote:

> 2)
>
> Another problem is that strlcpy() will also happily do bad stuff if we pass
> it a negative size. Instead of that we will from now on print a (one time)
> warning and return safely.

Hm, so this check is buggy, as 'size_t' is unsigned - and for some reason GCC
didn't warn about the never-met comparison and the resulting unreachable dead
code here:

> + /* Overflow check: */
> + if (unlikely(dest_size < 0)) {
> + WARN_ONCE(1, "strlcpy(): dest_size < 0 underflow!");
> + return strlen(src);
> + }

which is annoying.

Would people object to something like:

> + /* Overflow check: */
> + if (unlikely((ssize_t)dest_size < 0)) {
> + WARN_ONCE(1, "strlcpy(): dest_size < 0 underflow!");
> + return strlen(src);
> + }

?

As I doubt it's legit to have larger than 2GB strings.

Also, I'm wondering why GCC didn't warn.

Thanks,

Ingo


\
 
 \ /
  Last update: 2015-10-05 14:01    [W:0.036 / U:0.072 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site