php7.0: FTBFS on hurd-i386 (for review)
Source: php7.0
Version: 7.0.4-7
Severity: important
Tags: patch
User: debian-hurd@lists.debian.org
Usertags: hurd
Hello,
Currently php7.0 fails to build on GNU/Hurd due to PATH_MAX issues. The attached
patch 0051-ext_date_lib_parse_tz.c.patch solves this by allocating the strings
dynamically and free them when no longer needed.
Thanks!
Index: php7.0-7.0.4/ext/date/lib/parse_tz.c
===================================================================
--- php7.0-7.0.4.orig/ext/date/lib/parse_tz.c
+++ php7.0-7.0.4/ext/date/lib/parse_tz.c
@@ -428,17 +428,23 @@ static char *parse_iso6709(char *p, doub
static struct location_info **create_location_table(void)
{
struct location_info **li, *i;
- char zone_tab[PATH_MAX];
+ char *zone_tab = NULL;
+ int len;
char line[512];
FILE *fp;
- strncpy(zone_tab, ZONEINFO_PREFIX "/zone.tab", sizeof zone_tab);
+ len = strlen(ZONEINFO_PREFIX) + 9 + 1;
+ zone_tab = malloc(len);
+ strncpy(zone_tab, ZONEINFO_PREFIX "/zone.tab", len);
fp = fopen(zone_tab, "r");
if (!fp) {
+ free(zone_tab);
return NULL;
}
+ free(zone_tab);
+
li = calloc(LOCINFO_HASH_SIZE, sizeof *li);
while (fgets(line, sizeof line, fp)) {
@@ -568,12 +574,14 @@ static void create_zone_index(timelib_tz
do {
struct dirent **ents;
- char name[PATH_MAX], *top;
- int count;
+ char *name = NULL, *top;
+ int count, len;
/* Pop the top stack entry, and iterate through its contents. */
top = dirstack[--dirstack_top];
- snprintf(name, sizeof name, ZONEINFO_PREFIX "/%s", top);
+ len = strlen(ZONEINFO_PREFIX) + 1 + strlen(top) + 1;
+ name = malloc(len);
+ snprintf(name, len, ZONEINFO_PREFIX "/%s", top);
count = php_scandir(name, &ents, index_filter, php_alphasort);
@@ -581,7 +589,9 @@ static void create_zone_index(timelib_tz
struct stat st;
const char *leaf = ents[count - 1]->d_name;
- snprintf(name, sizeof name, ZONEINFO_PREFIX "/%s/%s",
+ len = strlen(ZONEINFO_PREFIX) + 1 + strlen(top) + 1 + strlen(leaf) + 1;
+ name = realloc(name, len);
+ snprintf(name, len, ZONEINFO_PREFIX "/%s/%s",
top, leaf);
if (strlen(name) && stat(name, &st) == 0) {
@@ -590,7 +600,9 @@ static void create_zone_index(timelib_tz
if (root[0] == '/') root++;
- snprintf(name, sizeof name, "%s%s%s", root,
+ len = strlen(root) + 1 + strlen(leaf) + 1;
+ name = realloc(name, len);
+ snprintf(name, len, "%s%s%s", root,
*root ? "/": "", leaf);
if (S_ISDIR(st.st_mode)) {
@@ -616,6 +628,7 @@ static void create_zone_index(timelib_tz
}
if (count != -1) free(ents);
+ free(name);
free(top);
} while (dirstack_top);
@@ -704,25 +717,31 @@ static const char *canonical_tzname(cons
* length of the mapped data is placed in *length. */
static char *map_tzfile(const char *timezone, size_t *length)
{
- char fname[PATH_MAX];
+ char *fname = NULL;
struct stat st;
char *p;
- int fd;
-
+ const char *c_tzname = canonical_tzname(timezone);
+ int fd, len;
+
if (timezone[0] == '\0' || strstr(timezone, "..") != NULL) {
return NULL;
}
- snprintf(fname, sizeof fname, ZONEINFO_PREFIX "/%s", canonical_tzname(timezone));
-
+ len = strlen(ZONEINFO_PREFIX) + 1 + strlen(c_tzname) + 1;
+ fname = malloc(len);
+ snprintf(fname, len, ZONEINFO_PREFIX "/%s", c_tzname);
+
fd = open(fname, O_RDONLY);
if (fd == -1) {
+ free(fname);
return NULL;
} else if (fstat(fd, &st) != 0 || !is_valid_tzfile(&st)) {
+ free(fname);
close(fd);
return NULL;
}
+ free(fname);
*length = st.st_size;
p = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
close(fd);
@@ -832,7 +851,9 @@ int timelib_timezone_id_is_valid(char *t
#ifdef HAVE_SYSTEM_TZDATA
if (tzdb == timezonedb_system) {
- char fname[PATH_MAX];
+ char *fname = NULL;
+ const char *c_tzname = canonical_tzname(timezone);
+ int len, res;
struct stat st;
if (timezone[0] == '\0' || strstr(timezone, "..") != NULL) {
@@ -846,9 +867,13 @@ int timelib_timezone_id_is_valid(char *t
}
}
- snprintf(fname, sizeof fname, ZONEINFO_PREFIX "/%s", canonical_tzname(timezone));
-
- return stat(fname, &st) == 0 && is_valid_tzfile(&st);
+ len = strlen(ZONEINFO_PREFIX) + 1 + strlen(c_tzname) + 1;
+ fname = malloc(len);
+ snprintf(fname, len, ZONEINFO_PREFIX "/%s", c_tzname);
+
+ res = (stat(fname, &st) == 0) && is_valid_tzfile(&st);
+ free(fname);
+ return res;
}
#endif
Reply to: