[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <30e5fd087ee6fbe992cde8f09d945ed160b0c117.1263675077.git.andre.goddard@gmail.com>
Date: Sat, 16 Jan 2010 18:57:01 -0200
From: André Goddard Rosa <andre.goddard@...il.com>
To: linux-kernel@...r.kernel.org, torvalds@...ux-foundation.org
Cc: André Goddard Rosa <andre.goddard@...il.com>,
Li Zefan <lizf@...fujitsu.com>,
Alex Riesen <raa.lkml@...il.com>,
Andrew Morton <akpm@...ux-foundation.org>
Subject: [PATCH 2/2] string: teach strnstr() to not search past NUL-terminator
As noticed by Alex Riesen at:
http://marc.info/?l=linux-kernel&m=126364040821071&w=2
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))
--
1.6.6.201.g56119
--
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