00db10
commit 45c30c61c9001867c1891f5862764f084e53f348
00db10
Author: Ondřej Bílka <neleai@seznam.cz>
00db10
Date:   Sun Oct 20 08:25:25 2013 +0200
00db10
00db10
    Replace alloca in __tzfile_read by malloc. Fixes bug 15670
00db10
00db10
diff --git a/time/tzfile.c b/time/tzfile.c
00db10
index 9dd5130..3ea3051 100644
00db10
--- a/time/tzfile.c
00db10
+++ b/time/tzfile.c
00db10
@@ -114,6 +114,7 @@ __tzfile_read (const char *file, size_t extra, char **extrap)
00db10
   int was_using_tzfile = __use_tzfile;
00db10
   int trans_width = 4;
00db10
   size_t tzspec_len;
00db10
+  char *new = NULL;
00db10
 
00db10
   if (sizeof (time_t) != 4 && sizeof (time_t) != 8)
00db10
     abort ();
00db10
@@ -145,22 +146,12 @@ __tzfile_read (const char *file, size_t extra, char **extrap)
00db10
   if (*file != '/')
00db10
     {
00db10
       const char *tzdir;
00db10
-      unsigned int len, tzdir_len;
00db10
-      char *new, *tmp;
00db10
 
00db10
       tzdir = getenv ("TZDIR");
00db10
       if (tzdir == NULL || *tzdir == '\0')
00db10
-	{
00db10
-	  tzdir = default_tzdir;
00db10
-	  tzdir_len = sizeof (default_tzdir) - 1;
00db10
-	}
00db10
-      else
00db10
-	tzdir_len = strlen (tzdir);
00db10
-      len = strlen (file) + 1;
00db10
-      new = (char *) __alloca (tzdir_len + 1 + len);
00db10
-      tmp = __mempcpy (new, tzdir, tzdir_len);
00db10
-      *tmp++ = '/';
00db10
-      memcpy (tmp, file, len);
00db10
+	tzdir = default_tzdir;
00db10
+      if (__asprintf (&new, "%s/%s", tzdir, file) == -1)
00db10
+	goto ret_free_transitions;
00db10
       file = new;
00db10
     }
00db10
 
00db10
@@ -170,11 +161,7 @@ __tzfile_read (const char *file, size_t extra, char **extrap)
00db10
       && stat64 (file, &st) == 0
00db10
       && tzfile_ino == st.st_ino && tzfile_dev == st.st_dev
00db10
       && tzfile_mtime == st.st_mtime)
00db10
-    {
00db10
-      /* Nothing to do.  */
00db10
-      __use_tzfile = 1;
00db10
-      return;
00db10
-    }
00db10
+    goto done;  /* Nothing to do.  */
00db10
 
00db10
   /* Note the file is opened with cancellation in the I/O functions
00db10
      disabled and if available FD_CLOEXEC set.  */
00db10
@@ -527,12 +514,15 @@ __tzfile_read (const char *file, size_t extra, char **extrap)
00db10
   __daylight = rule_stdoff != rule_dstoff;
00db10
   __timezone = -rule_stdoff;
00db10
 
00db10
+ done:
00db10
   __use_tzfile = 1;
00db10
+  free (new);
00db10
   return;
00db10
 
00db10
  lose:
00db10
   fclose (f);
00db10
  ret_free_transitions:
00db10
+  free (new);
00db10
   free ((void *) transitions);
00db10
   transitions = NULL;
00db10
 }