dm_strword: fix invalid memory access

Calling this dm_strword with an emtpy 'str' can cause invalid memory
access. This commit checks for an empty string.

NOTE: This function is insecure and can cause segfaults
      when 'str' is larger than 'source'

Signed-off-by: Daniel Danzberger <daniel@dd-wrt.com>
This commit is contained in:
Daniel Danzberger 2020-06-09 22:24:58 +02:00
parent 9ee0484353
commit 3b7fe9237b

View file

@ -1137,8 +1137,10 @@ static inline int isword_delim(char c)
char *dm_strword(char *src, char *str)
{
char *ret = src;
if (src[0] == '\0')
if (src[0] == 0 || str[0] == 0)
return NULL;
int len = strlen(str);
while ((ret = strstr(ret, str)) != NULL) {
if ((ret == src && isword_delim(ret[len])) ||