aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libbb/replace.c4
1 files changed, 4 insertions, 0 deletions
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;