about summary refs log tree commit diff
path: root/time/tst-strftime.c
diff options
context:
space:
mode:
authorPaul Pluzhnikov <ppluzhnikov@google.com>2015-09-26 13:27:48 -0700
committerPaul Pluzhnikov <ppluzhnikov@google.com>2015-09-26 13:27:48 -0700
commitd36c75fc0d44deec29635dd239b0fbd206ca49b7 (patch)
treeb6fe3c25e34b43ba630eeab1f493f5451601a798 /time/tst-strftime.c
parentfa752c698146ca3e9f7747d33059fbef9bb02b0e (diff)
downloadglibc-d36c75fc0d44deec29635dd239b0fbd206ca49b7.tar.gz
glibc-d36c75fc0d44deec29635dd239b0fbd206ca49b7.tar.xz
glibc-d36c75fc0d44deec29635dd239b0fbd206ca49b7.zip
Fix BZ #18985 -- out of range data to strftime() causes a segfault
Diffstat (limited to 'time/tst-strftime.c')
-rw-r--r--time/tst-strftime.c52
1 files changed, 51 insertions, 1 deletions
diff --git a/time/tst-strftime.c b/time/tst-strftime.c
index 374fba4262..af3ff72faf 100644
--- a/time/tst-strftime.c
+++ b/time/tst-strftime.c
@@ -4,6 +4,56 @@
 #include <time.h>
 
 
+static int
+do_bz18985 (void)
+{
+  char buf[1000];
+  struct tm ttm;
+  int rc, ret = 0;
+
+  memset (&ttm, 1, sizeof (ttm));
+  ttm.tm_zone = NULL;  /* Dereferenced directly if non-NULL.  */
+  rc = strftime (buf, sizeof (buf), "%a %A %b %B %c %z %Z", &ttm);
+
+  if (rc == 66)
+    {
+      const char expected[]
+	= "? ? ? ? ? ? 16843009 16843009:16843009:16843009 16844909 +467836 ?";
+      if (0 != strcmp (buf, expected))
+	{
+	  printf ("expected:\n  %s\ngot:\n  %s\n", expected, buf);
+	  ret += 1;
+	}
+    }
+  else
+    {
+      printf ("expected 66, got %d\n", rc);
+      ret += 1;
+    }
+
+  /* Check negative values as well.  */
+  memset (&ttm, 0xFF, sizeof (ttm));
+  ttm.tm_zone = NULL;  /* Dereferenced directly if non-NULL.  */
+  rc = strftime (buf, sizeof (buf), "%a %A %b %B %c %z %Z", &ttm);
+
+  if (rc == 30)
+    {
+      const char expected[] = "? ? ? ? ? ? -1 -1:-1:-1 1899  ";
+      if (0 != strcmp (buf, expected))
+	{
+	  printf ("expected:\n  %s\ngot:\n  %s\n", expected, buf);
+	  ret += 1;
+	}
+    }
+  else
+    {
+      printf ("expected 30, got %d\n", rc);
+      ret += 1;
+    }
+
+  return ret;
+}
+
 static struct
 {
   const char *fmt;
@@ -104,7 +154,7 @@ do_test (void)
 	}
     }
 
-  return result;
+  return result + do_bz18985 ();
 }
 
 #define TEST_FUNCTION do_test ()