|
Message-ID: <ce1320d8-60df-7c54-2348-6aabac63c24d@rasmusvillemoes.dk> Date: Tue, 23 Jul 2019 16:37:01 +0200 From: Rasmus Villemoes <linux@...musvillemoes.dk> To: Joe Perches <joe@...ches.com>, Linus Torvalds <torvalds@...ux-foundation.org>, linux-kernel@...r.kernel.org Cc: Jonathan Corbet <corbet@....net>, Stephen Kitt <steve@....org>, Kees Cook <keescook@...omium.org>, Nitin Gote <nitin.r.gote@...el.com>, jannh@...gle.com, kernel-hardening@...ts.openwall.com, Andrew Morton <akpm@...ux-foundation.org> Subject: Re: [PATCH V2 1/2] string: Add stracpy and stracpy_pad mechanisms On 23/07/2019 15.51, Joe Perches wrote: > Several uses of strlcpy and strscpy have had defects because the > last argument of each function is misused or typoed. > > Add macro mechanisms to avoid this defect. > > stracpy (copy a string to a string array) must have a string > array as the first argument (dest) and uses sizeof(dest) as the > count of bytes to copy. > > These mechanisms verify that the dest argument is an array of > char or other compatible types like u8 or s8 or equivalent. Sorry, but "compatible types" has a very specific meaning in C, so please don't use that word. And yes, the kernel disables -Wpointer-sign, so passing an u8* or s8* when strscpy() expects a char* is silently accepted, but does such code exist? > > V2: Use __same_type testing char[], signed char[], and unsigned char[] > Rename to, from, and size, dest, src and count count is just as bad as size in terms of "the expression src might contain that identifier". But there's actually no reason to even declare a local variable, just use ARRAY_SIZE() directly as the third argument to strscpy(). Rasmus
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.