From 529edce2b90c53f37b63a9a4b7f55fc4b4d3bf0c Mon Sep 17 00:00:00 2001 From: Yuxuan Shui Date: Sun, 1 Mar 2020 13:19:50 +0000 Subject: [PATCH] config_libconfig: eliminate relative paths from XDG_CONFIG_DIRS According to the XDG Base Directory Specification, relative paths in XDG_CONFIG_DIRS are invalid, so eliminate them if found. Signed-off-by: Yuxuan Shui --- src/config_libconfig.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/config_libconfig.c b/src/config_libconfig.c index 6326583d..5bc1020a 100644 --- a/src/config_libconfig.c +++ b/src/config_libconfig.c @@ -66,7 +66,7 @@ const char * const * xdgConfigDirectories(void) { } } - // Store the string and the result pointers together so it can be + // Store the string and the result pointers together so they can be // freed together char **dir_list = cvalloc(sizeof(char *) * (count + 2) + strlen(xdgd) + 1); auto dirs = strcpy((char *)dir_list + sizeof(char *) * (count + 2), xdgd); @@ -79,7 +79,16 @@ const char * const * xdgConfigDirectories(void) { path++; } dir_list[count] = path; - dir_list[count + 1] = NULL; + + size_t fill = 0; + for (size_t i = 0; i <= count; i++) { + if (dir_list[i][0] == '/') { + dir_list[fill] = dir_list[i]; + fill++; + } + } + + dir_list[fill] = NULL; return (const char * const *)dir_list; }