From c2dd1815c8873690c249545c64cf288359b40afb Mon Sep 17 00:00:00 2001 From: Boris Faure Date: Thu, 2 Jul 2020 23:45:32 +0200 Subject: [PATCH] termptyesc: avoid issues with cast from double + no buffer overflow --- src/bin/termptyesc.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/bin/termptyesc.c b/src/bin/termptyesc.c index 76e09918..ea3e4df5 100644 --- a/src/bin/termptyesc.c +++ b/src/bin/termptyesc.c @@ -3771,7 +3771,7 @@ _xterm_parse_intensity(Eina_Unicode *p, unsigned char *c, int len) char *endptr_double; double d; - while (l < 64 && len && p[0] && p[0] != '/' && p[0] != '\007' && p[0] < 128) + while (l < 63 && len && p[0] && p[0] != '/' && p[0] != '\007' && p[0] < 128) { buf[l++] = p[0]; len--; @@ -3785,7 +3785,11 @@ _xterm_parse_intensity(Eina_Unicode *p, unsigned char *c, int len) if (endptr_double == buf || d < 0 || d > 1.0 || isnan(d)) return -1; - *c = d * 255.0; + d *= 255.0; + if (d > 255.0) + *c = 255; + else + *c = round(d); return endptr_double - buf; }