emacs-diffs
[Top][All Lists]
Advanced

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

master 6eeab90632: Don't accept whitespace or hex floats in rgbi: colour


From: Mattias Engdegård
Subject: master 6eeab90632: Don't accept whitespace or hex floats in rgbi: colour specs
Date: Sun, 6 Mar 2022 08:08:00 -0500 (EST)

branch: master
commit 6eeab90632506348a58d264eb3304625756c8659
Author: Mattias Engdegård <mattiase@acm.org>
Commit: Mattias Engdegård <mattiase@acm.org>

    Don't accept whitespace or hex floats in rgbi: colour specs
    
    `color-values-from-color-spec` (new in Emacs 28) erroneously accepted
    leading whitespace and hex floats in rgbi: components.
    
    Reported by Philip Kaludercic.
    
    * src/xfaces.c (parse_float_color_comp): Disallow leading whitespace
    and hex floats.
    * test/src/xfaces-tests.el
    (xfaces-internal-color-values-from-color-spec): Add test cases.
---
 src/xfaces.c             | 5 +++++
 test/src/xfaces-tests.el | 5 ++++-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/xfaces.c b/src/xfaces.c
index 8100bdb157..1d2e2489de 100644
--- a/src/xfaces.c
+++ b/src/xfaces.c
@@ -888,6 +888,11 @@ parse_hex_color_comp (const char *s, const char *e, 
unsigned short *dst)
 static double
 parse_float_color_comp (const char *s, const char *e)
 {
+  /* Only allow decimal float literals without whitespace.  */
+  for (const char *p = s; p < e; p++)
+    if (!((*p >= '0' && *p <= '9')
+         || *p == '.' || *p == '+' || *p == '-' || *p == 'e' || *p == 'E'))
+      return -1;
   char *end;
   double x = strtod (s, &end);
   return (end == e && x >= 0 && x <= 1) ? x : -1;
diff --git a/test/src/xfaces-tests.el b/test/src/xfaces-tests.el
index 31c0f021b2..16f1653791 100644
--- a/test/src/xfaces-tests.el
+++ b/test/src/xfaces-tests.el
@@ -47,7 +47,10 @@
                  '(0 32768 6554)))
   (should (equal (color-values-from-color-spec "rgbi:1e-3/1.0e-2/1e0")
                  '(66 655 65535)))
-  (should (equal (color-values-from-color-spec "rgbi:0/0.5/10") nil)))
+  (should (equal (color-values-from-color-spec "rgbi:0/0.5/10") nil))
+  (should (equal (color-values-from-color-spec "rgbi:0/0/ 0") nil))
+  (should (equal (color-values-from-color-spec "rgbi:0/0x0/0") nil))
+  (should (equal (color-values-from-color-spec "rgbi:0/+0x1/0") nil)))
 
 (provide 'xfaces-tests)
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]