Added check for not going beyond the string lenght

This commit is contained in:
Luca Deri
2018-09-24 09:57:51 +02:00
parent 7117f0532c
commit f639c237a1
+4 -3
View File
@@ -5703,7 +5703,7 @@ char* ndpi_strnstr(const char *s, const char *find, size_t slen) {
size_t len; size_t len;
if((c = *find++) != '\0') { if((c = *find++) != '\0') {
len = strlen(find); len = strnlen(find, slen);
do { do {
do { do {
if(slen-- < 1 || (sc = *s++) == '\0') if(slen-- < 1 || (sc = *s++) == '\0')
@@ -5711,10 +5711,11 @@ char* ndpi_strnstr(const char *s, const char *find, size_t slen) {
} while (sc != c); } while (sc != c);
if(len > slen) if(len > slen)
return (NULL); return (NULL);
} while (strncmp(s, find, len) != 0); } while(strncmp(s, find, len) != 0);
s--; s--;
} }
return ((char *)s);
return((char *)s);
} }
/* ****************************************************** */ /* ****************************************************** */