Blame SOURCES/glibc-rh767693.patch

b9ba6d
commit 97ac2654b2d831acaa18a2b018b0736245903fd2
b9ba6d
Author: Ulrich Drepper <drepper@gmail.com>
b9ba6d
Date:   Sat Dec 17 20:18:42 2011 -0500
b9ba6d
b9ba6d
    Check values from TZ file header
b9ba6d
b9ba6d
b9ba6d
	[BZ #13506]
b9ba6d
	* time/tzfile.c (__tzfile_read): Check values from file header.
b9ba6d
b9ba6d
diff -ru a/time/tzfile.c b/time/tzfile.c
b9ba6d
--- a/time/tzfile.c	2010-05-04 11:27:23.000000000 +0000
b9ba6d
+++ b/time/tzfile.c	2011-12-19 06:39:49.875358578 +0000
b9ba6d
@@ -19,6 +19,7 @@
b9ba6d
 
b9ba6d
 #include <assert.h>
b9ba6d
 #include <limits.h>
b9ba6d
+#include <stdint.h>
b9ba6d
 #include <stdio.h>
b9ba6d
 #include <stdio_ext.h>
b9ba6d
 #include <stdlib.h>
b9ba6d
@@ -234,23 +235,58 @@
b9ba6d
       goto read_again;
b9ba6d
     }
b9ba6d
 
b9ba6d
+  if (__builtin_expect (num_transitions
b9ba6d
+			> ((SIZE_MAX - (__alignof__ (struct ttinfo) - 1))
b9ba6d
+			   / (sizeof (time_t) + 1)), 0))
b9ba6d
+    goto lose;
b9ba6d
   total_size = num_transitions * (sizeof (time_t) + 1);
b9ba6d
   total_size = ((total_size + __alignof__ (struct ttinfo) - 1)
b9ba6d
 		& ~(__alignof__ (struct ttinfo) - 1));
b9ba6d
   types_idx = total_size;
b9ba6d
-  total_size += num_types * sizeof (struct ttinfo) + chars;
b9ba6d
+  if (__builtin_expect (num_types
b9ba6d
+			> (SIZE_MAX - total_size) / sizeof (struct ttinfo), 0))
b9ba6d
+    goto lose;
b9ba6d
+  total_size += num_types * sizeof (struct ttinfo);
b9ba6d
+  if (__builtin_expect (chars > SIZE_MAX - total_size, 0))
b9ba6d
+    goto lose;
b9ba6d
+  total_size += chars;
b9ba6d
+  if (__builtin_expect (__alignof__ (struct leap) - 1
b9ba6d
+			> SIZE_MAX - total_size, 0))
b9ba6d
+    goto lose;
b9ba6d
   total_size = ((total_size + __alignof__ (struct leap) - 1)
b9ba6d
 		& ~(__alignof__ (struct leap) - 1));
b9ba6d
   leaps_idx = total_size;
b9ba6d
+  if (__builtin_expect (num_leaps
b9ba6d
+			> (SIZE_MAX - total_size) / sizeof (struct leap), 0))
b9ba6d
+    goto lose;
b9ba6d
   total_size += num_leaps * sizeof (struct leap);
b9ba6d
-  tzspec_len = (sizeof (time_t) == 8 && trans_width == 8
b9ba6d
-		? st.st_size - (ftello (f)
b9ba6d
-				+ num_transitions * (8 + 1)
b9ba6d
-				+ num_types * 6
b9ba6d
-				+ chars
b9ba6d
-				+ num_leaps * 12
b9ba6d
-				+ num_isstd
b9ba6d
-				+ num_isgmt) - 1 : 0);
b9ba6d
+  tzspec_len = 0;
b9ba6d
+  if (sizeof (time_t) == 8 && trans_width == 8)
b9ba6d
+    {
b9ba6d
+      off_t rem = st.st_size - ftello (f);
b9ba6d
+      if (__builtin_expect (rem < 0
b9ba6d
+			    || (size_t) rem < (num_transitions * (8 + 1)
b9ba6d
+					       + num_types * 6
b9ba6d
+					       + chars), 0))
b9ba6d
+	goto lose;
b9ba6d
+      tzspec_len = (size_t) rem - (num_transitions * (8 + 1)
b9ba6d
+				   + num_types * 6
b9ba6d
+				   + chars);
b9ba6d
+      if (__builtin_expect (num_leaps > SIZE_MAX / 12
b9ba6d
+			    || tzspec_len < num_leaps * 12, 0))
b9ba6d
+	goto lose;
b9ba6d
+      tzspec_len -= num_leaps * 12;
b9ba6d
+      if (__builtin_expect (tzspec_len < num_isstd, 0))
b9ba6d
+	goto lose;
b9ba6d
+      tzspec_len -= num_isstd;
b9ba6d
+      if (__builtin_expect (tzspec_len == 0 || tzspec_len - 1 < num_isgmt, 0))
b9ba6d
+	goto lose;
b9ba6d
+      tzspec_len -= num_isgmt + 1;
b9ba6d
+      if (__builtin_expect (SIZE_MAX - total_size < tzspec_len, 0))
b9ba6d
+	goto lose;
b9ba6d
+    }
b9ba6d
+  if (__builtin_expect (SIZE_MAX - total_size - tzspec_len < extra, 0))
b9ba6d
+    goto lose;
b9ba6d
 
b9ba6d
   /* Allocate enough memory including the extra block requested by the
b9ba6d
      caller.  */