From f12643039a650816dfe557eaefb864f8ab5c5901 Mon Sep 17 00:00:00 2001 From: Ikey Doherty Date: Tue, 19 Dec 2017 12:23:20 +0000 Subject: [PATCH] common: Return `realpath`'d config dir where possible This ensures we only use a sane realpath and collapse the slashes where we can to allow trivial string matching. Signed-off-by: Ikey Doherty --- src/common/files.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/common/files.c b/src/common/files.c index 568fbf5..c0dd887 100644 --- a/src/common/files.c +++ b/src/common/files.c @@ -55,9 +55,14 @@ char *lsi_get_user_config_dir() const char *home = NULL; char *c = NULL; char *xdg_config = getenv("XDG_CONFIG_HOME"); + char *p = NULL; /* Respect the XDG_CONFIG_HOME variable if it is set */ if (xdg_config) { + p = realpath(xdg_config, NULL); + if (p) { + return p; + } return strdup(xdg_config); } @@ -65,6 +70,11 @@ char *lsi_get_user_config_dir() if (asprintf(&c, "%s/.config", home) < 0) { return NULL; } + p = realpath(c, NULL); + if (p) { + free(c); + return p; + } return c; }