[PATCH 2/2] string: teach strnstr() to not search past NUL-terminator

From: Andrà Goddard Rosa
Date: Sun Jan 17 2010 - 16:00:25 EST


As noticed by Alex Riesen at:
http://marc.info/?l=linux-kernel&m=126364040821071&w=2

Signed-off-by: Andrà Goddard Rosa <andre.goddard@xxxxxxxxx>
cc: Li Zefan <lizf@xxxxxxxxxxxxxx>
cc: Alex Riesen <raa.lkml@xxxxxxxxx>
cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
---
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@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/