[tz] localtime crash and fix

Alois Treindl alois at astro.ch
Fri Nov 24 16:22:19 UTC 2023


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 at 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
>      }
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mm.icann.org/pipermail/tz/attachments/20231124/23a4b088/attachment.htm>


More information about the tz mailing list