diff options
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/replace.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/libbb/replace.c b/libbb/replace.c index a661d96..6183d3e 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; |