[hackers] [sbase] Fix issue with negative integers passed to expand(1) || FRIGN

From: <git_AT_suckless.org>
Date: Sun, 25 Jan 2015 15:30:39 +0100 (CET)

commit da6a1cd53cce9a16b31daa8cb0bfb617f0cb7e40
Author: FRIGN <dev_AT_frign.de>
Date: Sun Jan 25 15:24:48 2015 +0100

    Fix issue with negative integers passed to expand(1)
    
    WISDOM OF THE DAY: strtoul() does not error out, when it hits a '-'-sign.
    Instead, it happily carries on and fucks everything up.

diff --git a/expand.c b/expand.c
index 126fe32..3862afa 100644
--- a/expand.c
+++ b/expand.c
_AT_@ -6,9 +6,9 @@
 #include "utf.h"
 #include "util.h"
 
-static int iflag = 0;
-static size_t *tablist = NULL;
-static size_t tablistlen = 0;
+static int iflag = 0;
+static ssize_t *tablist = NULL;
+static size_t tablistlen = 0;
 
 static size_t
 parselist(const char *s, size_t slen)
_AT_@ -29,13 +29,13 @@ parselist(const char *s, size_t slen)
                         len++;
                 }
         }
- tablist = emalloc((len + 1) * sizeof(size_t));
+ tablist = emalloc((len + 1) * sizeof(ssize_t));
 
         m = 0;
         for (i = 0; i < slen; i += sep - (s + i) + 1) {
- tablist[m++] = strtoul(s + i, &sep, 10);
- if (tablist[m - 1] == 0)
- eprintf("expand: tab size can't be zero.\n");
+ tablist[m++] = strtol(s + i, &sep, 10);
+ if (tablist[m - 1] <= 0)
+ eprintf("expand: tab size can't be negative or zero.\n");
                 if (*sep && *sep != ',' && *sep != ' ')
                         eprintf("expand: invalid number in tablist.\n");
                 if (m > 1 && tablist[m - 1] < tablist[m - 2])
Received on Sun Jan 25 2015 - 15:30:39 CET

This archive was generated by hypermail 2.3.0 : Sun Jan 25 2015 - 15:36:10 CET