Tags: patch

Attached is a new version of:

   php7.0-7.0.14/debian/patches/0032-Use-system-timezone.patch

It verifies the files written by tzdata's debconf, /etc/timezone and
/etc/localtime, are consistent.  If they are it sets the guessed time
zone to be whatever is in /etc/timezone.  If they aren't Debian's
timezone isn't used, which currently means the guessed timezone will be
"UTC".

Obviously this only works on Debian, but since upstream rejected the
patch I doubt that's a problem.
From: Russell Stuart <russell-deb...@stuart.id.au>
Date: Tue,  3 Jan 2017 14:28:39 +1000
Subject: Use Debian timezone

Upstream don't want this patch. See
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=730771 for a summary.
---
 ext/date/php_date.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

--- a/ext/date/php_date.c
+++ b/ext/date/php_date.c
@@ -29,6 +29,7 @@
 #include "php_date.h"
 #include "zend_interfaces.h"
 #include "lib/timelib.h"
+#include <fcntl.h>
 #include <time.h>
 
 #ifdef PHP_WIN32
@@ -992,6 +993,47 @@
 		DATEG(timezone_valid) = 1;
 		return DATEG(default_timezone);
 	}
+	/* Use the timezone written by the tzdata packages debconf */
+	{
+		static char* debian_timezone = NULL;
+		struct stat localtime_st;
+		struct stat zoneinfo_st;
+		char zone_path[2048];
+		int bytes_read = 0;
+		int l;
+
+		if (debian_timezone == NULL) {
+			/* Verify the data written by tzdata debconf is self consistent */
+			int fd = open("/etc/timezone", O_RDONLY);
+			if (fd != -1) {
+				strcpy(zone_path, "/usr/share/zoneinfo/");
+				l = strlen(zone_path);
+				bytes_read = read(fd, zone_path + l, sizeof(zone_path) - l - 1);
+				close(fd);
+				if (bytes_read > 0) {
+					while (zone_path[l + bytes_read - 1] < ' ')
+						bytes_read -= 1;
+					zone_path[bytes_read + l] = '\0';
+					if (stat("/etc/localtime", &localtime_st) != -1 &&
+						stat(zone_path, &zoneinfo_st) != -1 &&
+						localtime_st.st_dev == zoneinfo_st.st_dev &&
+						localtime_st.st_ino == zoneinfo_st.st_ino &&
+						timelib_timezone_id_is_valid(zone_path + l, tzdb)
+					) {
+						debian_timezone = emalloc(bytes_read);
+						strcpy(debian_timezone, zone_path + l);
+					}
+				}
+			}
+		}
+		if (debian_timezone == NULL) {
+			debian_timezone = emalloc(1);
+			*debian_timezone = '\0';
+		}
+		if (*debian_timezone != '\0') {
+			return debian_timezone;
+		}
+	}
 	/* Fallback to UTC */
 	return "UTC";
 }

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to