From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/10642 Path: news.gmane.org!.POSTED!not-for-mail From: Hannu Nyman Newsgroups: gmane.linux.lib.musl.general Subject: Re: Bug in timezone handling (new zonename format like '<+04>-4' ) Date: Wed, 19 Oct 2016 09:40:18 +0300 Message-ID: References: <7d2a2332-05ee-6f5e-7ed9-26bf7b8e1aae@iki.fi> <20160331160647.GV21636@brightrain.aerifal.cx> <699b8fe9-4693-8f71-c321-452c765f26a3@iki.fi> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Trace: blaine.gmane.org 1476859243 22204 195.159.176.226 (19 Oct 2016 06:40:43 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 19 Oct 2016 06:40:43 +0000 (UTC) User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:51.0) Gecko/20100101 Thunderbird/51.0a2 To: musl@lists.openwall.com Original-X-From: musl-return-10655-gllmg-musl=m.gmane.org@lists.openwall.com Wed Oct 19 08:40:38 2016 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1bwkYD-0004QO-CR for gllmg-musl@m.gmane.org; Wed, 19 Oct 2016 08:40:33 +0200 Original-Received: (qmail 19897 invoked by uid 550); 19 Oct 2016 06:40:32 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 19879 invoked from network); 19 Oct 2016 06:40:31 -0000 X-Virus-Scanned: Debian amavisd-new at pp.htv.fi In-Reply-To: <699b8fe9-4693-8f71-c321-452c765f26a3@iki.fi> Content-Language: en-US Xref: news.gmane.org gmane.linux.lib.musl.general:10642 Archived-At: Reference to earlier discussion in March 2016: http://www.openwall.com/lists/musl/2016/03/31/10 I think that I have finally found the fix for the bug in handling timezone names. musl fails to parse timezone string if the zone name is defined in the quoted form with <>. Example: root@...nWrt:~# cat /etc/TZ <+04>-4 root@...nWrt:~# date Wed Mar 30 08:02:59 +04>-4 2016 (note that Openwrt/LEDE patches musl to use /etc/TZ instead of an environment variable, but that has no effect on the evaluation itself) All new timezones & changes to old ones since zoneinfo 2016b seem to adopt the new way, and old zone name abbreviations (like EET) are being gradually removed. Currently already 47 timezones have numeric names inside < >. Examples of new timezone strings (after 2016g): 'Antarctica/Troll', '<+00>0<+02>-2,M3.5.0/1,M10.5.0/3' 'Asia/Baku', '<+04>-4' 'Europe/Istanbul', '<+03>-3' 'Europe/Minsk', '<+03>-3' I think that I have now found the bug in musl and fixed it. The core reason is a fault in the logic for quoted timezone names in function "getname" in __tz.c. The name string evaluation loop forgets to push the pointer forward to get the next character. The pointer "*p" is explicitly moved one char forward to skip the "<" (and afterwards for ">"), but during the actual name evaluation loop the same "*p" is used until "i" reaches TZNAME_MAX and breaks the loop. After the loop, at the end of the function "*p" is increased by the (wrongly detected) length. _POSIX_TZNAME_MAX=6, so the name in the previous example is thought to be "+04>-4" as the whole loop evaluates against the first char "+" and does not notice the name end marker ">". http://git.musl-libc.org/cgit/musl/tree/src/time/__tz.c#n87 ``` if (**p == '<') { ++*p; for (i=0; **p!='>' && i /etc/TZ root@lede:~# cat /etc/TZ ; date UTC Tue Oct 18 18:46:53 UTC 2016 root@lede:~# echo "<+04>-4" > /etc/TZ root@lede:~# cat /etc/TZ ; date <+04>-4 Tue Oct 18 22:47:17 +04 2016 root@lede:~# echo "<+00>0<+02>-2,M3.5.0/1,M10.5.0/3" > /etc/TZ root@lede:~# cat /etc/TZ ; date <+00>0<+02>-2,M3.5.0/1,M10.5.0/3 Tue Oct 18 20:48:10 +02 2016 root@lede:~# echo "<-03>3" > /etc/TZ root@lede:~# cat /etc/TZ ; date <-03>3 Tue Oct 18 15:48:41 -03 2016 ```