From: Martin Lewis Date: Sun, 15 Sep 2019 16:51:30 +0000 (+0200) Subject: replace: count_strstr - Handle an edge case where sub is empty X-Git-Tag: 1_32_0~139 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=7011eca83afc313098f9869eea36742d4506bc02;p=oweals%2Fbusybox.git replace: count_strstr - Handle an edge case where sub is empty If sub is empty, avoids an infinite loop. function old new delta count_strstr 45 63 +18 Signed-off-by: Martin Lewis Signed-off-by: Denys Vlasenko --- diff --git a/libbb/replace.c b/libbb/replace.c index a661d96e6..6183d3e6f 100644 --- a/libbb/replace.c +++ b/libbb/replace.c @@ -15,6 +15,10 @@ unsigned FAST_FUNC count_strstr(const char *str, const char *sub) size_t sub_len = strlen(sub); unsigned count = 0; + /* If sub is empty, avoid an infinite loop */ + if (sub_len == 0) + return strlen(str) + 1; + while ((str = strstr(str, sub)) != NULL) { count++; str += sub_len;