]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
ls: avoid reading beyond end of color indicator
authorJim Meyering <meyering@redhat.com>
Fri, 30 Sep 2011 18:13:01 +0000 (20:13 +0200)
committerJim Meyering <meyering@redhat.com>
Fri, 30 Sep 2011 20:03:47 +0000 (22:03 +0200)
At first this looked like a buffer overrun, since there was no test
to ensure that the buffer length was 6.  However, since the LS_COLORS
string is NUL-terminated and since settings within it are separated by
":" there was neither the risk of reading beyond end of buffer nor risk
of a false-positive match.
* src/ls.c (print_color_indicator): Use color_symlink_as_referent
rather than manually comparing against "target" again.
* src/system.h (STRNCMP_LIT): Correct description in comment.

src/ls.c
src/system.h

index 680a7c315898da8f0dac06d3bf8d25e7d659e5ed..c1b19188cd5e4c625d2f4c6f29446504bf380566 100644 (file)
--- a/src/ls.c
+++ b/src/ls.c
@@ -4204,7 +4204,7 @@ print_color_indicator (const struct fileinfo *f, bool symlink_target)
         }
       else if (S_ISLNK (mode))
         type = ((!linkok
-                 && (!STRNCMP_LIT (color_indicator[C_LINK].string, "target")
+                 && (color_symlink_as_referent
                      || color_indicator[C_ORPHAN].string))
                 ? C_ORPHAN : C_LINK);
       else if (S_ISFIFO (mode))
index 107dbd5a64aedfd20c405f20399dd573c092ba76..ec64cd0d878a81c7a780a1cdf19145328698c00d 100644 (file)
@@ -188,7 +188,7 @@ select_plural (uintmax_t n)
 #define STREQ_LEN(a, b, n) (strncmp (a, b, n) == 0)
 #define STRPREFIX(a, b) (strncmp(a, b, strlen (b)) == 0)
 
-/* Just like strncmp, but the first argument must be a literal string
+/* Just like strncmp, but the second argument must be a literal string
    and you don't specify the length.  */
 #define STRNCMP_LIT(s, literal) \
   strncmp (s, "" literal "", sizeof (literal) - 1)