summaryrefslogtreecommitdiffstats
path: root/unix/tkUnixColor.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2012-03-21 22:23:32 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2012-03-21 22:23:32 (GMT)
commitea92b06db68f5c8092d262109b352f1b6e549e2a (patch)
treeba50b1fd6a8a5c99745e18058df4f0e31e290085 /unix/tkUnixColor.c
parent5d303234b64b5311926c1026be0cb08a83fdcfd3 (diff)
parenta7c65dfb59a48afb0ed95322f9ba7ad86790381a (diff)
downloadtk-ea92b06db68f5c8092d262109b352f1b6e549e2a.zip
tk-ea92b06db68f5c8092d262109b352f1b6e549e2a.tar.gz
tk-ea92b06db68f5c8092d262109b352f1b6e549e2a.tar.bz2
[Bug 2809525] Abort on overlong color name
Diffstat (limited to 'unix/tkUnixColor.c')
-rw-r--r--unix/tkUnixColor.c23
1 files changed, 6 insertions, 17 deletions
diff --git a/unix/tkUnixColor.c b/unix/tkUnixColor.c
index df754bd..9bfe8bb 100644
--- a/unix/tkUnixColor.c
+++ b/unix/tkUnixColor.c
@@ -126,20 +126,6 @@ TkpGetColor(
Colormap colormap = Tk_Colormap(tkwin);
XColor color;
TkColor *tkColPtr;
- char buf[100];
- unsigned len = strlen(name);
-
- /*
- * Make sure that we never exceed a reasonable length of color name. A
- * good maximum length is 99, arbitrary, but larger than any known color
- * name. [Bug 2809525]
- */
-
- if (len > 99) {
- len = 99;
- }
- memcpy(buf, name, len);
- buf[len] = '\0';
/*
* Map from the name to a pixel value. Call XAllocNamedColor rather than
@@ -150,7 +136,10 @@ TkpGetColor(
if (*name != '#') {
XColor screen;
- if (XAllocNamedColor(display, colormap, buf, &screen, &color) != 0) {
+ if (strlen(name) > 99) {
+ /* Don't bother to parse this. [Bug 2809525]*/
+ return (TkColor *) NULL;
+ } else if (XAllocNamedColor(display, colormap, name, &screen, &color) != 0) {
DeleteStressedCmap(display, colormap);
} else {
/*
@@ -160,13 +149,13 @@ TkpGetColor(
* approximation to the desired color.
*/
- if (XLookupColor(display, colormap, buf, &color, &screen) == 0) {
+ if (XLookupColor(display, colormap, name, &color, &screen) == 0) {
return NULL;
}
FindClosestColor(tkwin, &screen, &color);
}
} else {
- if (TkParseColor(display, colormap, buf, &color) == 0) {
+ if (TkParseColor(display, colormap, name, &color) == 0) {
return NULL;
}
if (XAllocColor(display, colormap, &color) != 0) {