[Fontconfig] Patch: crash in fontconfig

Frederic Crozat fontconfig@fontconfig.org
16 Jan 2003 09:41:18 +0100


--=-F5C7zNu/PdrKnUxQz53a
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hi, (this mail was already send to Keith before I discovered fontconfig mailing list :))

I've found a crasher in fontconfig when HOME variable is not set (it can
be the case when using usermode to get root access)..

I have done a patch which fixes this case and only rely on HOME
variable presence when getpwuid doesn't give any info..

-- 
Frederic Crozat <fcrozat@mandrakesoft.com>
MandrakeSoft

--=-F5C7zNu/PdrKnUxQz53a
Content-Disposition: inline; filename=fontconfig-2.1-gethome.patch
Content-Type: text/x-diff; name=fontconfig-2.1-gethome.patch; charset=ISO-8859-15
Content-Transfer-Encoding: 7bit

--- fontconfig/src/fcstr.c.gethome	2002-09-01 00:17:32.000000000 +0200
+++ fontconfig/src/fcstr.c	2003-01-08 18:26:11.000000000 +0100
@@ -25,6 +25,7 @@
 #include <stdlib.h>
 #include <ctype.h>
 #include <string.h>
+#include <pwd.h>
 #include "fcint.h"
 
 FcChar8 *
@@ -421,16 +422,38 @@
 }
 
 FcChar8 *
+FcStrGetHome (void)
+{
+	static FcChar8 * home;
+
+	if (!home) 
+	{
+	  struct passwd *pw;
+	  pw = getpwuid(getuid());
+	  if (pw) 
+	  {
+	    home = FcStrCopy (pw->pw_dir);
+	  }
+	  else {
+	    /* fallback on $HOME */
+	    home = (FcChar8 *) getenv ("HOME");
+	  }
+	}
+	return FcStrCopy (home);
+}
+
+FcChar8 *
 FcStrCopyFilename (const FcChar8 *s)
 {
     FcChar8 *new;
     
     if (*s == '~')
     {
-	FcChar8	*home = (FcChar8 *) getenv ("HOME");
-	int	size = strlen ((char *) home) + strlen ((char *) s);
+	FcChar8	*home = FcStrGetHome ();
+	int	size;
 	if (!home)
 	    return 0;
+	size = strlen ((char *) home) + strlen ((char *) s);
 	new = (FcChar8 *) malloc (size);
 	if (!new)
 	    return 0;
@@ -632,6 +655,7 @@
     return list->set->strs[list->n++];
 }
 
+
 void
 FcStrListDone (FcStrList *list)
 {
--- fontconfig/src/fccfg.c.gethome	2002-09-01 00:17:32.000000000 +0200
+++ fontconfig/src/fccfg.c	2003-01-08 18:22:58.000000000 +0100
@@ -1367,7 +1367,7 @@
     file = 0;
     switch (*url) {
     case '~':
-	dir = (FcChar8 *) getenv ("HOME");
+	dir = (FcChar8 *) FcStrGetHome();
 	if (dir)
 	    file = FcConfigFileExists (dir, url + 1);
 	else

--=-F5C7zNu/PdrKnUxQz53a--