From 8f2a807810c006e771c0f7429ba218a1ffb1e6de Mon Sep 17 00:00:00 2001 From: Patrick Lam Date: Fri, 18 Nov 2005 20:32:30 +0000 Subject: [PATCH] Don't crash when fc-cat invoked with no arguments. Fix invalid read access caused by premature free and GCC4 warnings in libxml2 codepath. reviewed by: plam reviewed by: plam --- ChangeLog | 17 ++++++++++++++++- fc-cat/fc-cat.c | 3 +++ src/fcxml.c | 10 ++++++---- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index f93693b..27f97b1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,19 @@ -2005-10-25 Jinghua Luo +2005-11-18 Frederic Crozat + reviewed by: plam + + * fc-cat/fc-cat.c (main): + + Don't crash when fc-cat invoked with no arguments. + +2005-11-18 Frederic Crozat + reviewed by: plam + + * src/fcxml.c (FcConfigSaveAttr, FcConfigParseAndLoad): + + Fix invalid read access caused by premature free and + GCC4 warnings in libxml2 codepath. + +2005-11-17 Jinghua Luo reviewed by: plam * src/fccfg.c (FcConfigValues): diff --git a/fc-cat/fc-cat.c b/fc-cat/fc-cat.c index 4f5b71d..4436512 100644 --- a/fc-cat/fc-cat.c +++ b/fc-cat/fc-cat.c @@ -325,6 +325,9 @@ main (int argc, char **argv) i = 1; #endif + if (i >= argc) + usage (argv[0]); + if (FcCacheFileRead (fs, dirs, dirname (strdup(argv[i])), argv[i])) FcCachePrintSet (fs, dirs, argv[i]); diff --git a/src/fcxml.c b/src/fcxml.c index b3777b9..57fd606 100644 --- a/src/fcxml.c +++ b/src/fcxml.c @@ -933,7 +933,7 @@ FcConfigSaveAttr (const XML_Char **attr) return 0; slen = 0; for (i = 0; attr[i]; i++) - slen += strlen (attr[i]) + 1; + slen += strlen ((char *) attr[i]) + 1; n = i; new = malloc ((i + 1) * sizeof (FcChar8 *) + slen); if (!new) @@ -2385,9 +2385,10 @@ FcConfigParseAndLoad (FcConfig *config, printf ("\tLoading config file %s\n", filename); f = fopen ((char *) filename, "r"); - FcStrFree (filename); - if (!f) + if (!f) { + FcStrFree (filename); goto bail0; + } #if ENABLE_LIBXML2 memset(&sax, 0, sizeof(sax)); @@ -2398,10 +2399,11 @@ FcConfigParseAndLoad (FcConfig *config, sax.endElement = FcEndElement; sax.characters = FcCharacterData; - p = xmlCreatePushParserCtxt (&sax, &parse, NULL, 0, filename); + p = xmlCreatePushParserCtxt (&sax, &parse, NULL, 0, (const char *) filename); #else p = XML_ParserCreate ("UTF-8"); #endif + FcStrFree (filename); if (!p) goto bail1; -- 2.39.5