← Commit list

7011eca83

Martin Lewis
Martin Lewis
2019-10-09
SUCCESS Duration: 156s

Subject

replace: count_strstr - Handle an edge case where sub is empty

Binary

No binary (build failed)

Architecture & Compiler Flags

Architecture: x86_64-linux-gnu Compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0

—

Build Log

(log yok)

Commit Diff GitHub →

libbb/replace.c+4 -0
@@ -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;