Skip to content

Commit f126430

Browse files
committed
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 <ikey@solus-project.com>
1 parent 7cfdd41 commit f126430

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/common/files.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,26 @@ char *lsi_get_user_config_dir()
5555
const char *home = NULL;
5656
char *c = NULL;
5757
char *xdg_config = getenv("XDG_CONFIG_HOME");
58+
char *p = NULL;
5859

5960
/* Respect the XDG_CONFIG_HOME variable if it is set */
6061
if (xdg_config) {
62+
p = realpath(xdg_config, NULL);
63+
if (p) {
64+
return p;
65+
}
6166
return strdup(xdg_config);
6267
}
6368

6469
home = lsi_get_home_dir();
6570
if (asprintf(&c, "%s/.config", home) < 0) {
6671
return NULL;
6772
}
73+
p = realpath(c, NULL);
74+
if (p) {
75+
free(c);
76+
return p;
77+
}
6878
return c;
6979
}
7080

0 commit comments

Comments
 (0)