[hackers] [sbase] Fix segmentation fault in tr(1) || FRIGN

From: <git_AT_suckless.org>
Date: Tue, 24 Mar 2015 23:53:16 +0100 (CET)

commit ee843a2e092059eca06c5ce5202c30fffa1b3a8f
Author: FRIGN <dev_AT_frign.de>
Date: Sat Jan 24 23:00:34 2015 +0100

    Fix segmentation fault in tr(1)
    
    and make the parser stricter.

diff --git a/tr.c b/tr.c
index e2e6b71..7aa71e7 100644
--- a/tr.c
+++ b/tr.c
_AT_@ -75,7 +75,7 @@ resolveescapes(Rune *r, size_t len)
 {
         size_t i, off, m, factor, q;
 
- for (i = 0; i < len - 1; i++) {
+ for (i = 0; i < len; i++) {
                 if (r[i] != '\\')
                         continue;
                 off = 0;
_AT_@ -97,7 +97,7 @@ resolveescapes(Rune *r, size_t len)
                                 if (r[m] < '0' || r[m] > '7')
                                         break;
                         if (m == i + 1)
- continue;
+ eprintf("tr: invalid escape sequence '\\%c'\n", r[i + 1]);
                         off += m - i - 1;
                         for (--m, q = 0, factor = 1; m > i; m--) {
                                 q += (r[m] - '0') * factor;
Received on Tue Mar 24 2015 - 23:53:16 CET

This archive was generated by hypermail 2.3.0 : Wed Mar 25 2015 - 00:02:49 CET