From 44826194e76d75fb06142fd16d97b7ad30bbb881 Mon Sep 17 00:00:00 2001 From: nick black Date: Sat, 27 Feb 2021 18:10:04 -0500 Subject: [PATCH] ncneofetch: eliminate PATH_MAX usage for Hurd #1375 --- src/fetch/main.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/fetch/main.c b/src/fetch/main.c index 394f48236..acdfb3f8f 100644 --- a/src/fetch/main.c +++ b/src/fetch/main.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -189,15 +190,20 @@ fetch_x_props(fetched_info* fi){ // Returns NULL if no such file can be found. Return value is heap-allocated. static char * get_xdg_logo(const char *spec){ - char logopath[PATH_MAX + 1]; // FIXME - int s = snprintf(logopath, sizeof(logopath) - 1, "%s/%s", "/usr/share/pixmaps/", spec); - if(s < 0 || (size_t)s >= sizeof(logopath)){ + const char* logopath = "/usr/share/pixmaps/"; + int dfd = open(logopath, O_CLOEXEC | O_DIRECTORY); + if(dfd < 0){ return NULL; } - if(access(logopath, F_OK) == 0){ - return strdup(logopath); + int r = faccessat(dfd, spec, R_OK, 0); + close(dfd); + if(r){ + return NULL; } - return NULL; + char* p = malloc(strlen(spec) + strlen(logopath) + 1); + strcpy(p, logopath); + strcat(p, spec); + return p; } // FIXME deal more forgivingly with quotation marks