Subject: Re: standards/21722: ISO-C conforming use of struct tm can crash
To: None <rearnsha@arm.com>
From: Simon Burge <simonb@wasabisystems.com>
List: netbsd-bugs
Date: 05/31/2003 00:06:58
Richard Earnshaw wrote:

> >Number:         21722
> >Category:       standards
> >Synopsis:       ISO-C conforming use of struct tm can crash
> 
> 	A program that makes use of only the fields in struct tm that are
> 	specified in the ISO-C standards can crash inside of strftime because
> 	the library accesses non-standard fields.
> 
> 	The following program sets all of the fields required by ISO-C and then
> 	calls strftime with a %Z template (an ISO-C documented option).
> 
> 	There is a similar problem with %z (part of c99) and use of the 
> 	tm_gmtoff.  But that only causes a bogus result to be returned.
> 
> 	
> >Fix:
> 	strftime and other time functions must not depend on non-iso fields
> 	being set when performing actions documented by the standard.

One `fix' would be to ignore (struct tm)->tm_zone when processing 'Z'
(ie, just remove the #ifdef TM_ZONE/#endif block in strftime.c) and use
only tzname[].  I think we can also use the timezone variable for 'z'
as well.

I don't know if this is the best way to fix this problem :-)


Simon.
--
Simon Burge                            <simonb@wasabisystems.com>
NetBSD Support and Service:         http://www.wasabisystems.com/