]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/color-names: Fix color name canonicalization
authorKarel Zak <kzak@redhat.com>
Tue, 15 Jul 2025 13:35:05 +0000 (15:35 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 15 Jul 2025 13:35:05 +0000 (15:35 +0200)
Return NULL rather than a random string if it cannot be translated to
the color sequence.

Signed-off-by: Karel Zak <kzak@redhat.com>
lib/color-names.c

index ec53e3d4770081224af5767856d79ad66535efaa..f7b1946090907578fd0718b0a13260f9925085da 100644 (file)
@@ -93,11 +93,14 @@ static int __color_canonicalize(const char *str, char **seq)
        *seq = NULL;
 
        /* convert color names like "red" to the real sequence */
-       if (*str != '\\' && isalpha(*str)) {
+       if (*str != '\\' && !strchr(str, ';') && isalpha(*str)) {
                const char *s = color_sequence_from_colorname(str);
-               *seq = strdup(s ? s : str);
 
-               return *seq ? 0 : -ENOMEM;
+               if (s) {
+                       *seq = strdup(s);
+                       return *seq ? 0 : -ENOMEM;
+               }
+               return 1;
        }
 
        /* convert xx;yy sequences to "\033[xx;yy" */