commit 6eec2eb3b48870435c9d729e8cf6dac44e2c3744
Author:     Pieter Kockx <[email protected]>
AuthorDate: Wed Oct 4 02:25:41 2017 +0200
Commit:     Michael Forney <[email protected]>
CommitDate: Sat Oct 21 12:44:09 2017 -0700

    tr: Fix infinite loop
    
    When `makeset` got a string containing square brackets
    followed by at least one extra character, e.g. "[abc]d",
    it entered an infinite loop because it was assumed
    `j` could not exceed `len` without having been equal to `len`.
    It can, however, when `m == len` and subsequently `j = m + 1`.

diff --git a/tr.c b/tr.c
index c235215..c5dbe7e 100644
--- a/tr.c
+++ b/tr.c
@@ -85,7 +85,7 @@ makeset(char *str, struct range **set, int (**check)(Rune))
                if (rstr[i] == '[') {
                        j = i;
 nextbrack:
-                       if (j == len)
+                       if (j >= len)
                                goto literal;
                        for (m = j; m < len; m++)
                                if (rstr[m] == ']') {

Reply via email to