aboutsummaryrefslogtreecommitdiff
path: root/src/lib/ndpi_main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/ndpi_main.c')
-rw-r--r--src/lib/ndpi_main.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/lib/ndpi_main.c b/src/lib/ndpi_main.c
index 0146f5b18..0cc57e19b 100644
--- a/src/lib/ndpi_main.c
+++ b/src/lib/ndpi_main.c
@@ -10533,10 +10533,18 @@ const char * ndpi_strncasestr(const char *s, const char *find, size_t len) {
const size_t s_len = strnlen(s, len);
+ /* If 'find' is longer than 's', no match is possible */
+ if (find_len > s_len) {
+ return NULL;
+ }
+
const char *const end_of_search = s + s_len - find_len + 1;
+ /* Cache the lowercased first character of 'find' */
+ const unsigned char fc = tolower((unsigned char) *find);
+
for (; s < end_of_search; ++s) {
- if (tolower((unsigned char)*s) == tolower((unsigned char)*find)) {
+ if (tolower((unsigned char)*s) == fc) {
if (strncasecmp(s + 1, find + 1, find_len - 1) == 0) {
return s;
}