On Tue, Jan 19, 2016 at 12:35:27PM +0100, Sunil Nimmagadda wrote:

> > -          dlen = strlen(dir);
> > -               while (dir[dlen-1] == '/')
> > -                       dir[--dlen] = '\0';     /* strip trailing '/' */

> dlen could never be zero as we are replacing dir[0] with '.' if
> it's an empty field but that has another problem of wrong strlen(3)
> values due to improper NUL termination. The simple fix is to skip
> empty fields in PATH which I committed.

Actually, the problem my diff was supposed to address is not empty
fields, but fields containing a slash and nothing else. Then,
dir[0] == '/' and dir[1] == '\0', so dlen == 1, and the while-loop
quoted above runs, and *decrements dlen* to 0. Then, to check if the
loop condition is still true, the program reads dir[-1]. If the
slash-only field is at the beginning of the path (e.g.,
PATH = "/:/bin:...") this means reading path[-1].

> These changes are committed. It's a good idea to split diffs where
> possible for ease of readability and review.

I'll do so in the future. Thanks for taking the time to check it.

Reply via email to