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.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,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 1620 invoked from network); 2 Jun 2021 15:41:49 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 2 Jun 2021 15:41:49 -0000 Received: (qmail 17718 invoked by uid 550); 2 Jun 2021 15:41:47 -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 17697 invoked from network); 2 Jun 2021 15:41:47 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; s=opensmtpd; bh=sgSxh0xZ4s okhrogTidBTia/3cMaZhld+amJuUCo8LM=; h=in-reply-to:references:from: subject:to:date; d=soeren-tempel.net; b=RIcyft6rxV17+2dClYIkewaEQuL89M xlAeBc7qwWl+Tf0ZlacMD6SsbhmzuVtKW0epf+xmPNnQa2EYOFfvOj8Wwv6zsvTdA/RFhA Qn6DCBQ0wdxtnO3G+FGI2X6eBFzOBg67AzUN9j5t/XjMd8mnQRdeZjBRX2oLBB9oTeW5xa c= Date: Wed, 02 Jun 2021 17:41:30 +0200 To: musl@lists.openwall.com From: =?UTF-8?Q?S=C3=B6ren?= Tempel References: <2V3462FZGWFIY.1YKM4G9ZM41UC@8pit.net> <20210425183841.GU2546@brightrain.aerifal.cx> <3S8Z66U5DDHBJ.3O9ZLGUXIRQWA@8pit.net> In-Reply-To: <3S8Z66U5DDHBJ.3O9ZLGUXIRQWA@8pit.net> Message-Id: <3MGPR9AUMAQHJ.2LO2SEGZT22CO@8pit.net> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [musl] Handling of non-location specific TZ values 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. Greetings, S=C3=B6ren S=C3=B6ren 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. >=20 > Maybe something along the following? Not too familiar with the musl code > base so not sure if including ctype.h is allowed etc. >=20 > 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, co= nst unsigned char *v, size_t > static void do_tzset() > { > char buf[NAME_MAX+25], *pathname=3Dbuf+24; > - const char *try, *s, *p; > + const char *try, *s, *orig; > const unsigned char *map =3D 0; > size_t i; > static const char search[] =3D > "/usr/share/zoneinfo/\0/share/zoneinfo/\0/etc/zoneinfo/\0"; >=20 > - s =3D getenv("TZ"); > + s =3D orig =3D getenv("TZ"); > if (!s) s =3D "/etc/localtime"; > if (!*s) s =3D __utc; >=20 > @@ -154,11 +155,19 @@ static void do_tzset() > } > if (old_tz) memcpy(old_tz, s, i+1); >=20 > - /* 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 =3D=3D ':' || ((p=3Dstrchr(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 =3D=3D ':' || (!isdigit(*s) && *s !=3D '+' && *s !=3D '-')) { > if (*s =3D=3D ':') s++; > + else if (orig) s =3D 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 =3D=3D '/' || *s =3D=3D '.') { > if (!libc.secure || !strcmp(s, "/etc/localtime")) > map =3D __map_file(s, &map_size); >=20 > Patch can be tested using date(1). For instance, compare the output of > `TZ=3DCET date` on a patched and unpatched system with an installed > zoneinfo database. >=20 > > 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=3DUTC cmd" to avoid any timezone shenanigans. >=20 > Maybe that can be done in a separate commit? >=20 > Greetings, > S=C3=B6ren