]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/colors: fix fallback to system directory
authorThomas Weißschuh <thomas@t-8ch.de>
Mon, 3 Feb 2025 20:46:13 +0000 (21:46 +0100)
committerThomas Weißschuh <thomas@t-8ch.de>
Mon, 3 Feb 2025 21:10:28 +0000 (22:10 +0100)
The current check relies on "*sfile" to recognize if a configuration has
been found in the current directory. However this condition is only true
for "type == UL_COLORFILE_SCHEME", breaking the .enable and .disable
configurations.
Instead reorder the logic a bit so that any valid configuration returns
rc == 0.

Reported-by: Axel <axel.scheepers76@gmail.com>
Link: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1094283
Reported-by: Chris Hofstaedtler <zeha@debian.org>
Link: https://lore.kernel.org/util-linux/Z5a08yD10L1J8AIa@per.namespace.at/
Tested-by: Chris Hofstaedtler <zeha@debian.org>
Fixes: 4bdf22803f9a ("lib/colors: ensure fallback to system directory")
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
lib/colors.c

index 4143c632e48a24548db0fc2ec0f762ce552e3d19..565a7171ba8c321ec2b34ea33ff0a9bcda6aafc1 100644 (file)
@@ -246,7 +246,7 @@ static int filename_to_tokens(const char *str,
 static int colors_readdir(struct ul_color_ctl *cc, const char *dirname)
 {
        DIR *dir;
-       int rc = 0;
+       int rc = -ENOENT;
        struct dirent *d;
        char sfile[PATH_MAX] = { '\0' };
        size_t namesz, termsz;
@@ -312,6 +312,7 @@ static int colors_readdir(struct ul_color_ctl *cc, const char *dirname)
                                        type == UL_COLORFILE_ENABLE ? "enable" : "???",
                                        cc->scores[type], score));
                cc->scores[type] = score;
+               rc = 0;
                if (type == UL_COLORFILE_SCHEME)
                        strncpy(sfile, d->d_name, sizeof(sfile));
        }
@@ -320,8 +321,6 @@ static int colors_readdir(struct ul_color_ctl *cc, const char *dirname)
                sfile[sizeof(sfile) - 1] = '\0';
                if (asprintf(&cc->sfile, "%s/%s", dirname, sfile) <= 0)
                        rc = -ENOMEM;
-       } else {
-               rc = -ENOENT;
        }
 
        closedir(dir);