You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ja...@apache.org on 2026/10/26 15:02:07 UTC
(mynewt-core) 04/07: libc/baselibc: Fix strnstr length handling
This is an automated email from the ASF dual-hosted git repository.
sjanc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
commit 8e62ae70963123312f82a9e45f647e7ef0b3c7d5
Author: Szymon Janc <sz...@codecoup.pl>
AuthorDate: Sun Oct 25 23:23:27 2026 +0100
libc/baselibc: Fix strnstr length handling
strnstr() limited the length of the needle instead of the haystack,
reading len bytes of needle regardless of its length and searching
the whole haystack. Search for the whole needle in at most len
characters of haystack.
Assisted-by: Claude:claude-opus-5-5
---
libc/baselibc/src/strstr.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/libc/baselibc/src/strstr.c b/libc/baselibc/src/strstr.c
index 0af23bbfd..f777b3d4e 100644
--- a/libc/baselibc/src/strstr.c
+++ b/libc/baselibc/src/strstr.c
@@ -12,5 +12,6 @@ char *strstr(const char *haystack, const char *needle)
char *strnstr(const char *haystack, const char *needle, size_t len)
{
- return (char *)memmem(haystack, strlen(haystack), needle, len);
+ return (char *)memmem(haystack, strnlen(haystack, len), needle,
+ strlen(needle));
}