From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 22797 invoked from network); 5 Jun 2021 15:52:27 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 5 Jun 2021 15:52:27 -0000 Received: (qmail 15429 invoked by uid 550); 5 Jun 2021 15:52:26 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 15411 invoked from network); 5 Jun 2021 15:52:25 -0000 Date: Sat, 5 Jun 2021 11:52:13 -0400 From: Rich Felker To: =?utf-8?B?U8O2cmVu?= Tempel Cc: musl@lists.openwall.com Message-ID: <20210605155213.GG13220@brightrain.aerifal.cx> References: <2V3462FZGWFIY.1YKM4G9ZM41UC@8pit.net> <20210425183841.GU2546@brightrain.aerifal.cx> <3S8Z66U5DDHBJ.3O9ZLGUXIRQWA@8pit.net> <3MGPR9AUMAQHJ.2LO2SEGZT22CO@8pit.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <3MGPR9AUMAQHJ.2LO2SEGZT22CO@8pit.net> User-Agent: Mutt/1.5.21 (2010-09-15) Subject: Re: [musl] Handling of non-location specific TZ values On Wed, Jun 02, 2021 at 05:41:30PM +0200, Sören Tempel wrote: > Ping. > > Would be willing to adjust the patch as needed. In any case, it would be > nice to get this fixed as it currently causes some test failures of > Alpine packages. Thanks for the ping. I had an alternate approach in draft that I want to look back at and compare. I'll try to get this fixed one way or the other before rolling the release. Rich > Sören Tempel wrote: > > Rich Felker wrote: > > > Yes. I suspect we can get by with calling getname with a dummy output > > > array, then checking if the next character is one of +, -, or a digit. > > > If not (in particular, if it's a null character) then we can attempt > > > loading it as a file. > > > > Maybe something along the following? Not too familiar with the musl code > > base so not sure if including ctype.h is allowed etc. > > > > diff --git a/src/time/__tz.c b/src/time/__tz.c > > index 09a6317e..6bc183d0 100644 > > --- a/src/time/__tz.c > > +++ b/src/time/__tz.c > > @@ -3,6 +3,7 @@ > > #include > > #include > > #include > > +#include > > #include > > #include "libc.h" > > #include "lock.h" > > @@ -125,13 +126,13 @@ static size_t zi_dotprod(const unsigned char *z, const unsigned char *v, size_t > > static void do_tzset() > > { > > char buf[NAME_MAX+25], *pathname=buf+24; > > - const char *try, *s, *p; > > + const char *try, *s, *orig; > > const unsigned char *map = 0; > > size_t i; > > static const char search[] = > > "/usr/share/zoneinfo/\0/share/zoneinfo/\0/etc/zoneinfo/\0"; > > > > - s = getenv("TZ"); > > + s = orig = getenv("TZ"); > > if (!s) s = "/etc/localtime"; > > if (!*s) s = __utc; > > > > @@ -154,11 +155,19 @@ static void do_tzset() > > } > > if (old_tz) memcpy(old_tz, s, i+1); > > > > - /* Non-suid can use an absolute tzfile pathname or a relative > > - * pathame beginning with "."; in secure mode, only the > > - * standard path will be searched. */ > > - if (*s == ':' || ((p=strchr(s, '/')) && !memchr(s, ',', p-s))) { > > + /* The TZ format specified by POSIX consists of a mandatory > > + * time zone name and a mandatory offset. We determine the > > + * name using getname, if the next character cannot constitute > > + * a valid offset (or the TZ value starts with a colon) we > > + * interpret the TZ environment variable as a zoneinfo file name. */ > > + getname(std_name, &s); > > + if (*s == ':' || (!isdigit(*s) && *s != '+' && *s != '-')) { > > if (*s == ':') s++; > > + else if (orig) s = orig; > > + > > + /* Non-suid can use an absolute tzfile pathname or a relative > > + * pathame beginning with "."; in secure mode, only the > > + * standard path will be searched. */ > > if (*s == '/' || *s == '.') { > > if (!libc.secure || !strcmp(s, "/etc/localtime")) > > map = __map_file(s, &map_size); > > > > Patch can be tested using date(1). For instance, compare the output of > > `TZ=CET date` on a patched and unpatched system with an installed > > zoneinfo database. > > > > > It might be worth adding a special exception for "UTC" and "GMT" so > > > that they are always interpreted as "UTC0" and "GMT0" and can't be > > > overridden by a bogus file in the zoneinfo path, for the sake of > > > software that does "TZ=UTC cmd" to avoid any timezone shenanigans. > > > > Maybe that can be done in a separate commit? > > > > Greetings, > > Sören