[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <4B53BDC5.1010201@cn.fujitsu.com>
Date: Mon, 18 Jan 2010 09:47:49 +0800
From: Li Zefan <lizf@...fujitsu.com>
To: André Goddard Rosa <andre.goddard@...il.com>
CC: linux-kernel@...r.kernel.org, torvalds@...ux-foundation.org,
Alex Riesen <raa.lkml@...il.com>,
Andrew Morton <akpm@...ux-foundation.org>
Subject: Re: [PATCH 2/2] string: teach strnstr() to not search past NUL-terminator
André Goddard Rosa wrote:
> As noticed by Alex Riesen at:
> http://marc.info/?l=linux-kernel&m=126364040821071&w=2
>
Please don't make this change, it's the user's responsibility
to make sure @len won't exceed @s1's length.
All the string functions of "n" version should work when
@s1 is not null-terminated, so don't call strlen() on @s1.
> Signed-off-by: André Goddard Rosa <andre.goddard@...il.com>
> cc: Li Zefan <lizf@...fujitsu.com>
> cc: Alex Riesen <raa.lkml@...il.com>
> cc: Andrew Morton <akpm@...ux-foundation.org>
> ---
> lib/string.c | 4 +++-
> 1 files changed, 3 insertions(+), 1 deletions(-)
>
> diff --git a/lib/string.c b/lib/string.c
> index 0f86245..94bad34 100644
> --- a/lib/string.c
> +++ b/lib/string.c
> @@ -689,11 +689,13 @@ EXPORT_SYMBOL(strstr);
> */
> char *strnstr(const char *s1, const char *s2, size_t len)
> {
> - size_t l1 = len, l2;
> + size_t l1, l2;
>
> l2 = strlen(s2);
> if (!l2)
> return (char *)s1;
> + l1 = strlen(s1);
> + l1 = (l1 <= len) ? l1 : len;
> while (l1 >= l2) {
> l1--;
> if (!memcmp(s1, s2, l2))
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists