mailing list of musl libc
 help / color / mirror / code / Atom feed
* Error in interpreting posix timezone TZ environment variable by musl-libc
@ 2014-10-08 19:44 vlse
  2014-10-08 20:59 ` Rich Felker
  0 siblings, 1 reply; 6+ messages in thread
From: vlse @ 2014-10-08 19:44 UTC (permalink / raw)
  To: musl

musl-libc stable 1.0.3 has wrong implementation of posix timezone TZ environmental variable.
For e.g. if I set TZ="IST-5:30" and use busybox date command compiled with musl-libc it's show One hour early than actual. Same with c code using asctime from musl-libc.

Any known fix.

------
 vlse



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Error in interpreting posix timezone TZ environment variable by musl-libc
  2014-10-08 19:44 Error in interpreting posix timezone TZ environment variable by musl-libc vlse
@ 2014-10-08 20:59 ` Rich Felker
  2014-10-08 21:11   ` Rich Felker
  0 siblings, 1 reply; 6+ messages in thread
From: Rich Felker @ 2014-10-08 20:59 UTC (permalink / raw)
  To: vlse; +Cc: musl

On Thu, Oct 09, 2014 at 01:14:29AM +0530, vlse wrote:
> musl-libc stable 1.0.3 has wrong implementation of posix timezone TZ environmental variable.
> For e.g. if I set TZ="IST-5:30" and use busybox date command
> compiled with musl-libc it's show One hour early than actual. Same
> with c code using asctime from musl-libc.
> 
> Any known fix.

Can you show the expected and actual output of the date command, both
with TZ=IST-5:30 and TZ=GMT?

Rich


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Error in interpreting posix timezone TZ environment variable by musl-libc
  2014-10-08 20:59 ` Rich Felker
@ 2014-10-08 21:11   ` Rich Felker
  2014-10-09  3:23     ` vlse
  0 siblings, 1 reply; 6+ messages in thread
From: Rich Felker @ 2014-10-08 21:11 UTC (permalink / raw)
  To: vlse; +Cc: musl

[-- Attachment #1: Type: text/plain, Size: 926 bytes --]

On Wed, Oct 08, 2014 at 04:59:18PM -0400, Rich Felker wrote:
> On Thu, Oct 09, 2014 at 01:14:29AM +0530, vlse wrote:
> > musl-libc stable 1.0.3 has wrong implementation of posix timezone TZ environmental variable.
> > For e.g. if I set TZ="IST-5:30" and use busybox date command
> > compiled with musl-libc it's show One hour early than actual. Same
> > with c code using asctime from musl-libc.
> > 
> > Any known fix.
> 
> Can you show the expected and actual output of the date command, both
> with TZ=IST-5:30 and TZ=GMT?

Never mind -- I found the bug. I have a patch attached for current git
master, and I think it will apply cleanly to 1.0.3 too, but I haven't
checked yet. I'll be making a new release (1.1.5) from the mainline
branch soon but an updated 1.0.x release might take longer since
there's nontrivial backporting work to be done for other bugs too. If
you have trouble applying the patch let me know.

Rich

[-- Attachment #2: tz_neg_off.diff --]
[-- Type: text/plain, Size: 764 bytes --]

diff --git a/src/time/__tz.c b/src/time/__tz.c
index 92c43a5..4ce2025 100644
--- a/src/time/__tz.c
+++ b/src/time/__tz.c
@@ -36,19 +36,16 @@ static int getint(const char **p)
 	return x;
 }
 
-static int getsigned(const char **p)
+static int getoff(const char **p)
 {
+	int neg = 0;
 	if (**p == '-') {
 		++*p;
-		return -getint(p);
+		neg = 1;
+	} else if (**p == '+') {
+		++*p;
 	}
-	if (**p == '+') ++*p;
-	return getint(p);
-}
-
-static int getoff(const char **p)
-{
-	int off = 3600*getsigned(p);
+	int off = 3600*getint(p);
 	if (**p == ':') {
 		++*p;
 		off += 60*getint(p);
@@ -57,7 +54,7 @@ static int getoff(const char **p)
 			off += getint(p);
 		}
 	}
-	return off;
+	return neg ? -off : off;
 }
 
 static void getrule(const char **p, int rule[5])

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Error in interpreting posix timezone TZ environment variable by musl-libc
  2014-10-08 21:11   ` Rich Felker
@ 2014-10-09  3:23     ` vlse
  2014-10-09  3:29       ` Rich Felker
  0 siblings, 1 reply; 6+ messages in thread
From: vlse @ 2014-10-09  3:23 UTC (permalink / raw)
  To: Rich Felker; +Cc: musl

Well, patch didn't apply cleanly to musl-1.0.3, but I patched it manually and compiled. It's fixed. Now musl correctly interprets posix TZ environment variables like TZ="IST-5:30". Also to note error occurs only when asctime program is staticly compiled not when compiled with shared musl library

------
 vlse



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Error in interpreting posix timezone TZ environment variable by musl-libc
  2014-10-09  3:23     ` vlse
@ 2014-10-09  3:29       ` Rich Felker
  2014-10-09  6:03         ` vlse
  0 siblings, 1 reply; 6+ messages in thread
From: Rich Felker @ 2014-10-09  3:29 UTC (permalink / raw)
  To: vlse; +Cc: musl

On Thu, Oct 09, 2014 at 08:53:38AM +0530, vlse wrote:
> Well, patch didn't apply cleanly to musl-1.0.3, but I patched it
> manually and compiled. It's fixed. Now musl correctly interprets
> posix TZ environment variables like TZ="IST-5:30".

Thanks for the report. I'll commit the changes.

> Also to note
> error occurs only when asctime program is staticly compiled not when
> compiled with shared musl library

I suspect you might have something wrong with your toolchain that's
causing dynamic linking to use the wrong libc. There's no reason the
dynamic libc.so should have been unaffected, so I think you might have
been using glibc or something else for dynamic linking...

Rich


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Error in interpreting posix timezone TZ environment variable by musl-libc
  2014-10-09  3:29       ` Rich Felker
@ 2014-10-09  6:03         ` vlse
  0 siblings, 0 replies; 6+ messages in thread
From: vlse @ 2014-10-09  6:03 UTC (permalink / raw)
  To: Rich Felker; +Cc: musl

Yes. It corrects TZ interpretation in both static as well as shared musl-libc. I was wrong about shared executable doesn't has this error!.

------
 vlse



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-10-09  6:03 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-08 19:44 Error in interpreting posix timezone TZ environment variable by musl-libc vlse
2014-10-08 20:59 ` Rich Felker
2014-10-08 21:11   ` Rich Felker
2014-10-09  3:23     ` vlse
2014-10-09  3:29       ` Rich Felker
2014-10-09  6:03         ` vlse

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).