]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
maint: avoid arbitrary memory access with buggy localtime()
authorPádraig Brady <P@draigBrady.com>
Mon, 9 Feb 2015 15:48:40 +0000 (15:48 +0000)
committerPádraig Brady <P@draigBrady.com>
Wed, 11 Feb 2015 00:35:08 +0000 (00:35 +0000)
* src/ls.c (align_nstrftime): Be defensive and validate the tm_mon
index before using to access the abmon array.  This was _not_ seen
to be an issue any system.  See https://bugzilla.redhat.com/1190454

src/ls.c

index cb9d3d6a2586e5c7a6145ec220f3a4a81ae3f2b4..4698520745002656e73539bdd25fb47025a904e5 100644 (file)
--- a/src/ls.c
+++ b/src/ls.c
@@ -3665,7 +3665,8 @@ align_nstrftime (char *buf, size_t size, char const *fmt, struct tm const *tm,
      the replacement is not done.  A malloc here slows ls down by 2%  */
   char rpl_fmt[sizeof (abmon[0]) + 100];
   const char *pb;
-  if (required_mon_width && (pb = strstr (fmt, "%b")))
+  if (required_mon_width && (pb = strstr (fmt, "%b"))
+      && 0 <= tm->tm_mon && tm->tm_mon <= 11)
     {
       if (strlen (fmt) < (sizeof (rpl_fmt) - sizeof (abmon[0]) + 2))
         {