Re: [hackers] [sbase][PATCH] tr gets stuck in infinite loop

From: Michael Forney <mforney_AT_mforney.org>
Date: Wed, 4 Oct 2017 23:16:29 -0700

On 2017-10-03, Pieter Kockx <pieterkockx_AT_gmail.com> wrote:
> Hello hackers
>
> tr '[a-z].' '[a-z]!'
>
> The salient feature here is that the square bracket part is followed by at
> least one extra character.
>
> This extra character will involve makeset in an infinite loop:
>
> // str = "[a]b"
> for (i = 0; i < len; i++) {
> if (rstr[i] == '[') {
> j = i;
> nextbrack:
> if (j == len) // (3) j==3 but len==4
> // (6) INFINITE LOOP
> goto literal;
> for (m = j; m < len; m++) // (4) mlen
> if (rstr[m] == ']') {
> j = m; // (1) j==2 and m==2
> break;
> }
>
> // all conditions in between are false
>
> j = m + 1; // (2) j == 3
> // (5) j == len+1
> goto nextbrack;
> }
>
> literal:
> // not reached
>
> Changing j == len to j >= len feels like sweeping the bug under the carpet.
>
> Thoughts?

Hi Pieter,

Thanks for the patch and the analysis. I've been looking through the
code but am still a bit confused about the intended behavior (and the
purpose of nextbrack), so I can't really tell if your fix is correct
or not.

I'll try to take a closer look this weekend.
Received on Thu Oct 05 2017 - 08:16:29 CEST

This archive was generated by hypermail 2.3.0 : Thu Oct 05 2017 - 08:24:22 CEST