[prev in list] [next in list] [prev in thread] [next in thread]
List: busybox
Subject: Re: [PATCH] replace: count_strstr - Handle an edge case where sub is empty
From: Denys Vlasenko <vda.linux () googlemail ! com>
Date: 2019-10-10 12:53:01
Message-ID: CAK1hOcPA0UGw4piE430_LjFXb3G3ZijGUfz3d=hmj62he9ysBQ () mail ! gmail ! com
[Download RAW message or body]
Applied, thanks
On Sun, Sep 15, 2019 at 6:52 PM Martin Lewis <martin.lewis.x84@gmail.com> wrote:
>
> If sub is empty, avoids an infinite loop.
>
> Signed-off-by: Martin Lewis <martin.lewis.x84@gmail.com>
> ---
> libbb/replace.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/libbb/replace.c b/libbb/replace.c
> index a661d96..6183d3e 100644
> --- a/libbb/replace.c
> +++ b/libbb/replace.c
> @@ -11,14 +11,18 @@
> #include "libbb.h"
>
> 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;
> }
> return count;
> }
>
> --
> 1.9.1
>
> _______________________________________________
> busybox mailing list
> busybox@busybox.net
> http://lists.busybox.net/mailman/listinfo/busybox
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic