From 04e846f33403058cd4b0e5c951c5a08e836782fd Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Wed, 14 Feb 2018 23:45:20 -0800
Subject: [PROPOSED 2/2] Allow specialized usage without TZDIR

Suggested by Manuela Friedrich for MS-Windows in:
https://mm.icann.org/pipermail/tz/2018-February/026228.html
* localtime.c (tzloadbody) [SUPPRESS_TZDIR]: Do not prepend TZDIR/
to relative names if TZDIR is empty.
---
 Makefile    | 2 ++
 NEWS        | 5 +++++
 localtime.c | 6 ++++++
 3 files changed, 13 insertions(+)

diff --git a/Makefile b/Makefile
index ad3b123..47acbbd 100644
--- a/Makefile
+++ b/Makefile
@@ -208,6 +208,8 @@ LDLIBS=
 #  -DRESERVE_STD_EXT_IDS if your platform reserves standard identifiers
 #	with external linkage, e.g., applications cannot define 'localtime'.
 #  -Dssize_t=long on hosts like MS-Windows that lack ssize_t
+#  -DSUPPRESS_TZDIR to not prepend TZDIR to file names; this has
+#	security implemencations and is not recommended for general use
 #  -DTHREAD_SAFE to make localtime.c thread-safe, as POSIX requires;
 #	not needed by the main-program tz code, which is single-threaded.
 #	Append other compiler flags as needed, e.g., -pthread on GNU/Linux.
diff --git a/NEWS b/NEWS
index 09ee326..999522b 100644
--- a/NEWS
+++ b/NEWS
@@ -50,6 +50,11 @@ Unreleased, experimental changes
       already can use vanguard.zi; in this respect, current tzcode is
       bleeding-edge.
 
+    When built with -DSUPPRESS_TZDIR, the tzcode library no longer
+    prepends TZDIR/ to file names that do not begin with '/'.  This is
+    not recommended for general use, due to its security implications.
+    (From a suggestion by Manuela Friedrich.)
+
   Changes to code
 
     zic now accepts subsecond precision in expressions like
diff --git a/localtime.c b/localtime.c
index 6f5aa76..b6b82bb 100644
--- a/localtime.c
+++ b/localtime.c
@@ -400,7 +400,13 @@ tzloadbody(char const *name, struct state *sp, bool doextend,
 
 	if (name[0] == ':')
 		++name;
+#ifdef SUPPRESS_TZDIR
+	/* Do not prepend TZDIR.  This is intended for specialized
+	   applications only, due to its security implications.  */
+	doaccess = true;
+#else
 	doaccess = name[0] == '/';
+#endif
 	if (!doaccess) {
 		size_t namelen = strlen(name);
 		if (sizeof lsp->fullname - sizeof tzdirslash <= namelen)
-- 
2.7.4

