Re: lib/60452: gmtime, gmtime_r put wrong time zone into result

"Robert Elz via gnats" <[email protected]>
Newsgroups gmane.os.netbsd.bugs
Message-ID <[email protected]>
The following reply was made to PR lib/60452; it has been noted by GNATS.

From: Robert Elz <[email protected]>
To: Thomas Klausner <[email protected]>
Cc: [email protected]
Subject: Re: lib/60452: gmtime, gmtime_r put wrong time zone into result
Date: Fri, 17 Jul 2026 04:22:38 +0700

     Date:        Thu, 16 Jul 2026 20:46:25 +0200
     From:        Thomas Klausner <[email protected]>
     Message-ID:  <[email protected]>
 
   | macOS:
   | ./test.sh: line 3: 53331 Segmentation fault: 11  TZ=Etc/GMT+7 ./jq
   | ./test.sh: line 4: 53332 Segmentation fault: 11  ./jq
   |
   | Debian:
   | Segmentation fault
   | Segmentation fault
   |
   | FreeBSD:
   | In-address space security exception (core dumped)
   | In-address space security exception (core dumped)
 
 Then they're all just using tm_zone, which means a properly conforming
 C application is likely to fail, as it cannot init that field, all it
 can do is leave random stack garbage in its place if it uses strftime
 to format a date/time which it has (for example) parsed into a struct
 tm from some other source (and it uses strftime %Z - which the C standard
 does define).
 
 The trash init of the tm_zone field I added to jq.c, and you tested, was
 just to simulate that random stack garbage, which gmtime() would never
 leave, but which alternate code to fill the struct tm would have no option
 but to do (using memset() as that code does would help, but is not a
 requirement).
 
 Perhaps that is acceptable, I'm not sure.   Using the tm_gmtoff and
 tm_zone fields certainly makes strftime much simpler to implement.
 
 kre
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.