[PATCH 13/13] lib/colors: assert rathen than overflow

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



lib/colors.c: In function 'colors_read_schemes':
lib/colors.c:412:7: warning: potential null pointer dereference [-Wnull-dereference]
  *out = '\0';
  ~~~~~^~~~~~

Signed-off-by: Sami Kerola <kerolasa@xxxxxx>
---
 lib/colors.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lib/colors.c b/lib/colors.c
index 4b280fe27..baafe0a90 100644
--- a/lib/colors.c
+++ b/lib/colors.c
@@ -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,7 @@ static int cn_sequence(const char *str, char **seq)
 		}
 		in++;
 	}
+	assert (len < (out - *seq));
 	*out = '\0';
 
 	return 0;
-- 
2.12.0

--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux