From 3b7fe9237b740c85f8654d231dd243c3eb94033b Mon Sep 17 00:00:00 2001 From: Daniel Danzberger Date: Tue, 9 Jun 2020 22:24:58 +0200 Subject: [PATCH] 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 --- libbbf_api/dmcommon.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libbbf_api/dmcommon.c b/libbbf_api/dmcommon.c index 6a7ba611..81fc2cb3 100644 --- a/libbbf_api/dmcommon.c +++ b/libbbf_api/dmcommon.c @@ -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])) ||