lkml.org 
[lkml]   [2003]   [Nov]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH 2.6]: IPv6: strcpy -> strlcpy
From
Date
On Thu, 2003-11-27 at 23:19, Russell King wrote:

> You misunderstand me. Consider the difference between:

OK, it's perfectly clear now :-)

> Note my final sentence there. Consider the following:
>
> char foo[256];
>
> strlcpy(foo, "hello", sizeof(foo);
>
> copy_to_user(uptr, foo, sizeof(foo));
>
> That ends up writing uninitialised kernel data to (unprivileged) user
> space. So would strcpy() used in that situation.
>
> strncpy() on the other hand, will zero the rest of the buffer (on x86
> at least) but you'll have to manually ensure that there is a terminator
> on the end. Or, you use strlcpy but memset the entire space you're
> copying the string into beforehand, which could be wasteful.
>
> Note: we should really fix the generic strncpy() - there are places in
> the kernel source which rely on the x86 strncpy() behaviour today (eg,
> binfmt_*.c core file generation.)

So, as I see:

1. We should fix strncpy()
2. I should replace strlcpy() with strncpy() in my patches.


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:58    [from the cache]
©2003-2011 Jasper Spaans