tr: fix "access past the end of a string" bug 4354
authorDenis Vlasenko <vda.linux@googlemail.com>
Sat, 26 Jul 2008 19:34:00 +0000 (19:34 -0000)
committerDenis Vlasenko <vda.linux@googlemail.com>
Sat, 26 Jul 2008 19:34:00 +0000 (19:34 -0000)
coreutils/tr.c

index e439fcb5b03a792a7b1385298e2acb374f90df5a..28798fe4ff5d0c0ddbec58a2d3ffd3fc6b286d8f 100644 (file)
@@ -138,7 +138,7 @@ static unsigned int expand(const char *arg, char *buffer)
                                arg += 3;       /* skip CHAR=] */
                                continue;
                        }
-                       if (*arg != '-') { /* not [x-...] - copy verbatim */
+                       if (i == '\0' || *arg != '-') { /* not [x-...] - copy verbatim */
                                *buffer++ = '[';
                                arg--; /* points to x */
                                continue; /* copy all, including eventual ']' */