unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: "Mattias Engdegård" <mattiase@acm.org>
To: Philip Kaludercic <philipk@posteo.net>
Cc: 54263@debbugs.gnu.org, Lars Ingebrigtsen <larsi@gnus.org>
Subject: bug#54263: 29.0.50; color-values-from-color-spec accepts whitespace in rgbi: specifications
Date: Sun, 6 Mar 2022 10:56:26 +0100	[thread overview]
Message-ID: <C6A74E3B-C562-4BC6-B926-AC88B24317F9@acm.org> (raw)
In-Reply-To: <87v8wswcsf.fsf@posteo.net>

[-- Attachment #1: Type: text/plain, Size: 285 bytes --]

> I haven't seen the function being used anywhere up until now (which doesn't have to mean anything), but considering that this is a relatively niche edge-case I would say that the bug should either be solved now or never. 

Let's solve it now then. I'm to blame, patch attached.


[-- Attachment #2: 0001-Don-t-accept-leading-whitespace-in-rgbi-colour-specs.patch --]
[-- Type: application/octet-stream, Size: 1888 bytes --]

From 0433c23ce12ea24bcb4de93b92b92070cf257310 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mattias=20Engdeg=C3=A5rd?= <mattiase@acm.org>
Date: Sun, 6 Mar 2022 10:50:27 +0100
Subject: [PATCH] Don't accept leading whitespace in rgbi: colour specs

`color-values-from-color-spec` (new in Emacs 28) erroneously accepted
leading whitespace in rgbi: components.

Reported by Philip Kaludercic.

* src/xfaces.c (parse_float_color_comp): Disallow leading whitespace.
* test/src/xfaces-tests.el
(xfaces-internal-color-values-from-color-spec): Add test case.
---
 src/xfaces.c             | 4 ++++
 test/src/xfaces-tests.el | 3 ++-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/xfaces.c b/src/xfaces.c
index 8100bdb157..7fbc667dfd 100644
--- a/src/xfaces.c
+++ b/src/xfaces.c
@@ -888,6 +888,10 @@ 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)
 {
+  if (s >= e ||
+      !(*s == '0' || *s == '1' || *s == '.' || *s == '+' || *s == '-'))
+    /* No leading whitespace permitted.  */
+    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..1175874144 100644
--- a/test/src/xfaces-tests.el
+++ b/test/src/xfaces-tests.el
@@ -47,7 +47,8 @@ xfaces-internal-color-values-from-color-spec
                  '(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)))
 
 (provide 'xfaces-tests)
 
-- 
2.32.0 (Apple Git-132)


  parent reply	other threads:[~2022-03-06  9:56 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-05 17:05 bug#54263: 29.0.50; color-values-from-color-spec accepts whitespace in rgbi: specifications Philip Kaludercic
2022-03-05 19:06 ` Lars Ingebrigtsen
2022-03-05 20:28   ` Philip Kaludercic
2022-03-06  9:56 ` Mattias Engdegård [this message]
2022-03-06 10:45   ` Philip Kaludercic
2022-03-06 11:12     ` Mattias Engdegård
2022-03-06 11:23       ` Mattias Engdegård
2022-03-06 12:47         ` Eli Zaretskii
2022-03-06 13:08           ` Mattias Engdegård
2022-03-06 14:06             ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=C6A74E3B-C562-4BC6-B926-AC88B24317F9@acm.org \
    --to=mattiase@acm.org \
    --cc=54263@debbugs.gnu.org \
    --cc=larsi@gnus.org \
    --cc=philipk@posteo.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).