From 29cf48b934fcc4f82a33d9ca8137fc1c3807d078 Mon Sep 17 00:00:00 2001 From: Christophe CURIS Date: Sun, 16 May 2021 15:47:06 +0200 Subject: [PATCH] WPrefs: Provide fall-back colour in the case of colour name not found As reported by Coverity (CID #331571), we did not check the return value of the call to XParseColor. If the function is given a colour name that it does not know, we would return an uninitialised colour. Signed-off-by: Christophe CURIS --- WPrefs.app/Appearance.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/WPrefs.app/Appearance.c b/WPrefs.app/Appearance.c index 909812d2..aed1e95b 100644 --- a/WPrefs.app/Appearance.c +++ b/WPrefs.app/Appearance.c @@ -446,12 +446,18 @@ static void str2rcolor(RContext * rc, const char *name, RColor * color) { XColor xcolor; - XParseColor(rc->dpy, rc->cmap, name, &xcolor); - - color->alpha = 255; - color->red = xcolor.red >> 8; - color->green = xcolor.green >> 8; - color->blue = xcolor.blue >> 8; + if (XParseColor(rc->dpy, rc->cmap, name, &xcolor) != 0) { + color->alpha = 255; + color->red = xcolor.red >> 8; + color->green = xcolor.green >> 8; + color->blue = xcolor.blue >> 8; + } else { + /* Color Name was not found - Return white instead */ + color->alpha = 255; + color->red = 255; + color->green = 255; + color->blue = 255; + } } static void dumpRImage(const char *path, RImage * image)