]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/colors: assert rathen than overflow [-Wnull-dereference]
authorKarel Zak <kzak@redhat.com>
Mon, 13 Mar 2017 13:44:22 +0000 (14:44 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 13 Mar 2017 13:44:22 +0000 (14:44 +0100)
lib/colors.c: In function 'colors_read_schemes':
lib/colors.c:412:7: warning: potential null pointer dereference [-Wnull-dereference]

Reported-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
lib/colors.c

index 4b280fe2702b4617f1b82260d0d32e8ae1cacdd5..dda6170574d931c291f71ef4c20755c24259b8a0 100644 (file)
@@ -342,6 +342,7 @@ static char *colors_get_homedir(char *buf, size_t bufsz)
 static int cn_sequence(const char *str, char **seq)
 {
        char *in, *out;
+       int len;
 
        if (!str)
                return -EINVAL;
@@ -357,7 +358,7 @@ static int cn_sequence(const char *str, char **seq)
        }
 
        /* convert xx;yy sequences to "\033[xx;yy" */
-       if (asprintf(seq, "\033[%sm", str) < 1)
+       if ((len = asprintf(seq, "\033[%sm", str)) < 1)
                return -ENOMEM;
 
        for (in = *seq, out = *seq; in && *in; in++) {
@@ -409,6 +410,8 @@ static int cn_sequence(const char *str, char **seq)
                }
                in++;
        }
+
+       assert ((out - *seq) <= len);
        *out = '\0';
 
        return 0;