[36/59] Remove arbitrary limit on TZ, TZDIR lengths

Message ID 20250105055750.1668721-37-eggert@cs.ucla.edu (mailing list archive)
State New
Headers
Series time: sync mktime from Gnulib |

Checks

Context Check Description
redhat-pt-bot/TryBot-apply_patch success Patch applied to master at the time it was sent

Commit Message

Paul Eggert Jan. 5, 2025, 5:57 a.m. UTC
  * time/tzfile.c (__tzfile_read): Don't use __asprintf, as it
mishandles strings longer than INT_MAX.
---
 time/tzfile.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
  

Patch

diff --git a/time/tzfile.c b/time/tzfile.c
index bd6df16b00..678ecdd58b 100644
--- a/time/tzfile.c
+++ b/time/tzfile.c
@@ -176,8 +176,15 @@  __tzfile_read (const char *file)
       tzdir = getenv ("TZDIR");
       if (tzdir == NULL || *tzdir == '\0')
 	tzdir = default_tzdir;
-      if (__asprintf (&new, "%s/%s", tzdir, file) == -1)
+
+      size_t tzdirlen = strlen (tzdir);
+      size_t filelen = strlen (file);
+      new = malloc (tzdirlen + 1 + filelen + 1);
+      if (new == NULL)
 	goto ret_free_transitions;
+      char *newp = __mempcpy (new, tzdir, tzdirlen);
+      *newp++ = '/';
+      __mempcpy (newp, file, filelen + 1);
       file = new;
     }