summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2006-04-25 08:18:30 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2006-04-25 08:18:30 (GMT)
commit9ec1ef976a52f570d9dc3ee204a4e6c50dd8a2b4 (patch)
treeb923a16380b0cf0a39a39479ef49b3d417616a9b
parent263d954b7df60ef3995be0abbe89ab617b900e25 (diff)
downloadtk-9ec1ef976a52f570d9dc3ee204a4e6c50dd8a2b4.zip
tk-9ec1ef976a52f570d9dc3ee204a4e6c50dd8a2b4.tar.gz
tk-9ec1ef976a52f570d9dc3ee204a4e6c50dd8a2b4.tar.bz2
Stop crashes when bad font names received from XServer. [Bug 1475865]
-rw-r--r--ChangeLog7
-rw-r--r--unix/tkUnixFont.c23
2 files changed, 26 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 18e8c4d..62f6ed9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2006-04-25 Donal K. Fellows <donal.k.fellows@manchester.ac.uk>
+
+ * unix/tkUnixFont.c (TkpGetFontFamilies): Fix crash caused when the
+ XServer returns invalid font names. [Bug 1475865]
+
2006-04-23 Vince Darley <vincentdarley@users.sourceforge.net>
* tests/scrollbar.test: fix to tkAqua test failures
@@ -16,7 +21,7 @@
* generic/tkWindow.c (Tk_NameToWindow): Allow NULL interp to
Tk_NameToWindow. This fixes TkGetWindowFromObj which promises to
handle NULL but didn't.
-
+
* generic/tkGrid.c: Fixed handling of out of bounds row or column.
* tests/grid.test: [Bug 1432666]
diff --git a/unix/tkUnixFont.c b/unix/tkUnixFont.c
index e4718d8..9140023 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.27 2006/03/22 00:21:19 das Exp $
+ * RCS: @(#) $Id: tkUnixFont.c,v 1.28 2006/04/25 08:18:31 dkf Exp $
*/
#include "tkUnixInt.h"
@@ -844,8 +844,25 @@ TkpGetFontFamilies(
Tcl_InitHashTable(&familyTable, TCL_STRING_KEYS);
nameList = ListFonts(Tk_Display(tkwin), "*", &numNames);
for (i = 0; i < numNames; i++) {
- family = strchr(nameList[i] + 1, '-') + 1;
- strchr(family, '-')[0] = '\0';
+ char *familyEnd;
+
+ family = strchr(nameList[i] + 1, '-');
+ if (family == NULL) {
+ /*
+ * Apparently, sometimes ListFonts() can return a font name with
+ * zero or one '-' character in it. This is probably indicative of
+ * a server misconfiguration, but crashing because of it is a very
+ * bad idea anyway. [Bug 1475865]
+ */
+
+ continue;
+ }
+ family++; /* Advance to char after '-'. */
+ familyEnd = strchr(family, '-');
+ if (familyEnd == NULL) {
+ continue; /* See comment above. */
+ }
+ *familyEnd = '\0';
Tcl_CreateHashEntry(&familyTable, family, &new);
}
XFreeFontNames(nameList);