[PATCH 36/59] Remove arbitrary limit on TZ, TZDIR lengths
Paul Eggert
eggert@cs.ucla.edu
Sun Jan 5 05:57:11 GMT 2025
* 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(-)
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;
}
--
2.45.2
More information about the Libc-alpha
mailing list