From 5004e8e01f5de30ad01904e57ea0eda006ab3a0c Mon Sep 17 00:00:00 2001 From: Akira TAGOH Date: Mon, 30 Jun 2014 12:37:36 +0900 Subject: [PATCH] Don't read/write from/to the XDG dirs if the home directory is disabled --- src/fccfg.c | 18 +++++++++++++++--- src/fcxml.c | 23 ++++++++++++++++++++++- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/fccfg.c b/src/fccfg.c index 8b62e52..73c45c8 100644 --- a/src/fccfg.c +++ b/src/fccfg.c @@ -2014,8 +2014,12 @@ FcConfigXdgCacheHome (void) else { const FcChar8 *home = FcConfigHome (); - size_t len = home ? strlen ((const char *)home) : 0; + size_t len; + if (!home) + return NULL; + + len = strlen ((const char *)home); ret = malloc (len + 7 + 1); if (ret) { @@ -2039,8 +2043,12 @@ FcConfigXdgConfigHome (void) else { const FcChar8 *home = FcConfigHome (); - size_t len = home ? strlen ((const char *)home) : 0; + size_t len; + if (!home) + return NULL; + + len = strlen ((const char *)home); ret = malloc (len + 8 + 1); if (ret) { @@ -2064,8 +2072,12 @@ FcConfigXdgDataHome (void) else { const FcChar8 *home = FcConfigHome (); - size_t len = home ? strlen ((const char *)home) : 0; + size_t len; + if (!home) + return NULL; + + len = strlen ((const char *)home); ret = malloc (len + 13 + 1); if (ret) { diff --git a/src/fcxml.c b/src/fcxml.c index 3dc1357..29dd4d6 100644 --- a/src/fcxml.c +++ b/src/fcxml.c @@ -2051,7 +2051,14 @@ FcParseDir (FcConfigParse *parse) attr = FcConfigGetAttribute (parse, "prefix"); if (attr && FcStrCmp (attr, (const FcChar8 *)"xdg") == 0) + { prefix = FcConfigXdgDataHome (); + /* home directory might be disabled. + * simply ignore this element. + */ + if (!prefix) + goto bail; + } data = FcStrBufDoneStatic (&parse->pstack->str); if (!data) { @@ -2142,11 +2149,18 @@ static void FcParseCacheDir (FcConfigParse *parse) { const FcChar8 *attr; - FcChar8 *prefix = NULL, *p, *data; + FcChar8 *prefix = NULL, *p, *data = NULL; attr = FcConfigGetAttribute (parse, "prefix"); if (attr && FcStrCmp (attr, (const FcChar8 *)"xdg") == 0) + { prefix = FcConfigXdgCacheHome (); + /* home directory might be disabled. + * simply ignore this element. + */ + if (!prefix) + goto bail; + } data = FcStrBufDone (&parse->pstack->str); if (!data) { @@ -2254,7 +2268,14 @@ FcParseInclude (FcConfigParse *parse) deprecated = FcTrue; attr = FcConfigGetAttribute (parse, "prefix"); if (attr && FcStrCmp (attr, (const FcChar8 *)"xdg") == 0) + { prefix = FcConfigXdgConfigHome (); + /* home directory might be disabled. + * simply ignore this element. + */ + if (!prefix) + goto bail; + } if (prefix) { size_t plen = strlen ((const char *)prefix);