Re: [tz] localtime crash and fix

That is effectively the same. But I would rather if Paul Eggert fixed the code. When I diff localtime.c from 2023c release with the current github version, there are changes which are obscure to me. The use of union to save memory is dangerous, in my opinion. There is no need in today's machines to save a few kilobytes of RAM for a process. Not even in embedded software for watches. It makes the code obscure. I have the gut feeling that the bug is in the line sp->goahead = ts->goahead; where ts has inherited old data from a previous call. On 24.11.23 16:54, Carlo wrote:
Dear Alois
Have you tried using this, letting the compiler perform the memset:
#else union local_storage ls = {0}; return tzloadbody(name, sp, doextend, &ls); #endif
On Thu, Nov 23, 2023 at 7:32 PM Alois Treindl via tz <tz@iana.org> wrote:
I have observed occasional crashes in localtime.c in the current github version.
In one of my applications, localtime() is called multiple times for several zones.
The condition when the segmentation fault appears are herd to reproduce or demonstrate.
This patch in function tzload() however solves the issue:
--- localtime.c 2023-11-16 20:18:01.904577574 +0100 +++ a/localtime.c 2023-11-23 19:22:21.062249899 +0100 @@ -769,6 +769,7 @@ } #else union local_storage ls; + memset(&ls, 0, sizeof(ls)); return tzloadbody(name, sp, doextend, &ls); #endif }

On 2023-11-24 08:22, Alois Treindl via tz wrote:
The use of union to save memory is dangerous, in my opinion. There is no need in today's machines to save a few kilobytes of RAM for a process. Not even in embedded software for watches.
When the memory is on the stack it still makes sense in some cases to save even a few kilobytes of RAM, as highly-threaded apps often have surprisingly small stacks. And anyway, the union has nothing to do with this particular bug. Thanks for reporting the problem. I installed the attached patches. The first patch fixes the bug; the second is a minor cleanup I noticed while in the neighborhood. The first patch clears just two slots rather than the entire struct, to avoid masking other errors.
participants (2)
-
Alois Treindl
-
Paul Eggert