From: "André Goddard Rosa" <andre.goddard@gmail.com>
To: linux-kernel@vger.kernel.org, torvalds@linux-foundation.org
Cc: "André Goddard Rosa" <andre.goddard@gmail.com>,
"Li Zefan" <lizf@cn.fujitsu.com>,
"Alex Riesen" <raa.lkml@gmail.com>,
"Andrew Morton" <akpm@linux-foundation.org>
Subject: [PATCH 2/2] string: teach strnstr() to not search past NUL-terminator
Date: Sat, 16 Jan 2010 18:57:01 -0200 [thread overview]
Message-ID: <30e5fd087ee6fbe992cde8f09d945ed160b0c117.1263675077.git.andre.goddard@gmail.com> (raw)
In-Reply-To: <cover.1263675077.git.andre.goddard@gmail.com>
As noticed by Alex Riesen at:
http://marc.info/?l=linux-kernel&m=126364040821071&w=2
Signed-off-by: André Goddard Rosa <andre.goddard@gmail.com>
cc: Li Zefan <lizf@cn.fujitsu.com>
cc: Alex Riesen <raa.lkml@gmail.com>
cc: Andrew Morton <akpm@linux-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
next prev parent reply other threads:[~2010-01-17 21:00 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-16 20:56 [PATCH 0/2] Fix recently introduced strnstr() to not search past NUL André Goddard Rosa
2010-01-16 20:57 ` [PATCH 1/2] string: simplify stricmp() André Goddard Rosa
2010-01-23 0:27 ` Andrew Morton
2010-01-23 1:47 ` Linus Torvalds
2010-01-16 20:57 ` André Goddard Rosa [this message]
2010-01-17 23:47 ` [PATCH 2/2] string: teach strnstr() to not search past NUL-terminator Alex Riesen
2010-01-18 1:47 ` Li Zefan
2010-01-18 15:10 ` André Goddard Rosa
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=30e5fd087ee6fbe992cde8f09d945ed160b0c117.1263675077.git.andre.goddard@gmail.com \
--to=andre.goddard@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lizf@cn.fujitsu.com \
--cc=raa.lkml@gmail.com \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®