summaryrefslogtreecommitdiffstats
path: root/unix
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2012-03-21 22:22:53 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2012-03-21 22:22:53 (GMT)
commit6db610bb79fd5283c600f956e518fcafb974ae8e (patch)
treea523b8d182e2349f2bfa0950f4d219e0ddd31c6c /unix
parente82ec654c94d1f0ae357d10c1e9ab6df5830b720 (diff)
parent06a17431086a4c08e2111ef5942d49759f7b3687 (diff)
downloadtk-6db610bb79fd5283c600f956e518fcafb974ae8e.zip
tk-6db610bb79fd5283c600f956e518fcafb974ae8e.tar.gz
tk-6db610bb79fd5283c600f956e518fcafb974ae8e.tar.bz2
[Bug 2809525] Abort on overlong color name
Diffstat (limited to 'unix')
-rw-r--r--unix/tkUnixColor.c23
1 files changed, 6 insertions, 17 deletions
diff --git a/unix/tkUnixColor.c b/unix/tkUnixColor.c
index d3dba23..a455118 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) {