Applied, thanks!
On Thu, Jun 11, 2020 at 3:45 PM Martin Lewis wrote:
>
> Code shrink and prevention of possible out of bounds access.
>
> function old new delta
> nth_string36 26 -10
> --
> (add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-10) Total: -10 bytes
>textdata bss dec hex filename
> 981342 169151872 1000129 f42c1 busybox_old
> 981332 169151872 1000119 f42b7 busybox_unstripped
>
> Signed-off-by: Martin Lewis
> ---
> libbb/compare_string_array.c | 7 +--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/libbb/compare_string_array.c b/libbb/compare_string_array.c
> index 01a9df0e2..a06e57d3d 100644
> --- a/libbb/compare_string_array.c
> +++ b/libbb/compare_string_array.c
> @@ -117,8 +117,11 @@ int FAST_FUNC index_in_substrings(const char *strings,
> const char *key)
> const char* FAST_FUNC nth_string(const char *strings, int n)
> {
> while (n) {
> - n--;
> - strings += strlen(strings) + 1;
> + if (*strings++ == '\0') {
> + if (*strings == '\0') /* reached end of strings */
> + break;
> + n--;
> + }
> }
> return strings;
> }
> --
> 2.11.0
>
> ___
> 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