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