[hackers] [sbase] tr: Fix infinite loop || Pieter Kockx

From: <git_AT_suckless.org>
Date: Sat, 21 Oct 2017 21:57:39 +0200 (CEST)

commit 6eec2eb3b48870435c9d729e8cf6dac44e2c3744
Author: Pieter Kockx <pieterkockx_AT_gmail.com>
AuthorDate: Wed Oct 4 02:25:41 2017 +0200
Commit: Michael Forney <mforney_AT_mforney.org>
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
_AT_@ -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] == ']') {
Received on Sat Oct 21 2017 - 21:57:39 CEST

This archive was generated by hypermail 2.3.0 : Sat Oct 21 2017 - 22:00:21 CEST