Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <hna3gs3xbflf6xp3wahrue7vyxtkoinqt6vubo3uasr7lm5psq@gcun4mvwdol5>
Date: Sun, 6 Apr 2025 21:57:35 +0200
From: Alejandro Colomar <alx@...nel.org>
To: Rich Felker <dalias@...c.org>
Cc: ipedrosa@...hat.com, musl@...ts.openwall.com, 
	~hallyn/shadow@...ts.sr.ht
Subject: strptime("UTC", "%Z", &tm) in musl

Hi Rich,

I was trying to develop a function that parses a UTC date in the shadow
project, and I came up with this:
<https://github.com/shadow-maint/shadow/pull/1217/>

	$ grepc -htfd get_date .
	static long
	get_date(const char *s)
	{
		struct tm   tm;
		const char  *p;

		bzero(&tm, sizeof(tm));

		p = strptime("UTC", "%Z", &tm);
		if (p == NULL || !streq(p, ""))
			return -1;

		p = strptime(s, "%F", &tm);
		if (p == NULL || !streq(p, ""))
			return -1;

		return dategm(&tm);
	}

Which works fine in glibc, but fails in musl.

	$ grepc -tfd strptime . | sed -n '/case .Z.:/,/break/p'
		case 'Z':
			if (!strncmp(s, tzname[0], len = strlen(tzname[0]))) {
				tm->tm_isdst = 0;
				s += len;
			} else if (!strncmp(s, tzname[1], len=strlen(tzname[1]))) {
				tm->tm_isdst = 1;
				s += len;
			} else {
				/* FIXME: is this supposed to be an error? */
				while ((*s|32)-'a' <= 'z'-'a') s++;
			}
			break;

It seems "%Z" only accepts the timezone specified in the current locale
(via tzname), but doesn't accept parsing a different timezone (in this
case, I want specifically UTC, regardless of the locale).  I'd say this
is a bug, and an important limitation, BTW.

Is there any way I can workaround this for musl?


Have a lovely day!
Alex

-- 
<https://www.alejandro-colomar.es/>
<https://www.alejandro-colomar.es:8443/>
<http://www.alejandro-colomar.es:8080/>

Download attachment "signature.asc" of type "application/pgp-signature" (834 bytes)

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.