From e9e5d0ba7342f709080090857d9d37ea07a49c81 Mon Sep 17 00:00:00 2001 From: Po Lu Date: Fri, 21 Jan 2022 11:37:19 +0800 Subject: [PATCH] Fix BadValue crash when looking up empty color names on some X servers * src/xterm.c (x_parse_color): Avoid parsing empty color names. --- src/xterm.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/xterm.c b/src/xterm.c index 5adbf210be3..a53f2982c6b 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -2789,8 +2789,9 @@ x_query_frame_background_color (struct frame *f, XColor *bgcolor) and names we've actually looked up; list-colors-display is probably the most color-intensive case we're likely to hit. */ -Status x_parse_color (struct frame *f, const char *color_name, - XColor *color) +Status +x_parse_color (struct frame *f, const char *color_name, + XColor *color) { /* Don't pass #RGB strings directly to XParseColor, because that follows the X convention of zero-extending each channel @@ -2819,6 +2820,10 @@ Status x_parse_color (struct frame *f, const char *color_name, } } + /* Some X servers send BadValue on empty color names. */ + if (!strlen (color_name)) + return 0; + if (XParseColor (dpy, cmap, color_name, color) == 0) /* No caching of negative results, currently. */ return 0; -- 2.39.5