From: "Mattias Engdegård" <mattiase@acm.org>
To: "Mattias Engdegård" <mattiase@acm.org>
Cc: 54263@debbugs.gnu.org, Philip Kaludercic <philipk@posteo.net>,
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 12:23:46 +0100 [thread overview]
Message-ID: <6E51015D-D59B-4120-8411-86F0909B4BDD@acm.org> (raw)
In-Reply-To: <832485F0-60AE-48E6-B163-0DF031F31028@acm.org>
[-- Attachment #1: Type: text/plain, Size: 124 bytes --]
The previous patch erroneously accepted "rgbi:0/+0x0/0". Here is one that doesn't try to be clever.
Clear for emacs-28?
[-- Attachment #2: 0001-Don-t-accept-whitespace-or-hex-floats-in-rgbi-colour.patch --]
[-- Type: application/octet-stream, Size: 2151 bytes --]
From e7bc68ae2f8e78278280a11d0392f52226f50449 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 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 @@ 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))
+ (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)
--
2.32.0 (Apple Git-132)
next prev parent reply other threads:[~2022-03-06 11:23 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
2022-03-06 10:45 ` Philip Kaludercic
2022-03-06 11:12 ` Mattias Engdegård
2022-03-06 11:23 ` Mattias Engdegård [this message]
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6E51015D-D59B-4120-8411-86F0909B4BDD@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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.