diff options
Diffstat (limited to 'unix')
-rw-r--r-- | unix/tkUnixFont.c | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/unix/tkUnixFont.c b/unix/tkUnixFont.c index ff2a705..1428b79 100644 --- a/unix/tkUnixFont.c +++ b/unix/tkUnixFont.c @@ -9,7 +9,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkUnixFont.c,v 1.3 1998/09/14 18:23:57 stanton Exp $ + * RCS: @(#) $Id: tkUnixFont.c,v 1.4 1998/11/25 01:48:54 stanton Exp $ */ #include "tkPort.h" @@ -127,6 +127,35 @@ TkpGetNativeFont(tkwin, name) CONST char *name; /* Platform-specific font name. */ { XFontStruct *fontStructPtr; + char *p; + int hasSpace, dashes, hasWild; + + /* + * The behavior of X when given a name that isn't an XLFD is unspecified. + * For example, Exceed 6 returns a valid font for any random string. This + * is awkward since system names have higher priority than the other Tk + * font syntaxes. So, we need to perform a quick sanity check on the + * name and fail if it looks suspicious. We fail if the name: + * - contains a space immediately before a dash + * - contains a space, but no '*' characters and fewer than 14 dashes + */ + + hasSpace = dashes = hasWild = 0; + for (p = name; *p != '\0'; p++) { + if (*p == ' ') { + if (p[1] == '-') { + return NULL; + } + hasSpace = 1; + } else if (*p == '-') { + dashes++; + } else if (*p == '*') { + hasWild = 1; + } + } + if ((dashes < 14) && !hasWild && hasSpace) { + return NULL; + } fontStructPtr = XLoadQueryFont(Tk_Display(tkwin), name); if (fontStructPtr == NULL) { |