Re: NULL pointer dereference in tai64nlocal

Charles Cazabon <[email protected]> Thu, 12 Sep 2013 07:05:24 -0600
Newsgroups gmane.comp.djb.syslog
Message-ID <[email protected]>
Rick Myers <[email protected]> wrote:
> > Thus said [email protected] on Tue, 10 Sep 2013 18:56:58 +1000:
> > 
> > > # echo @ | tai64nlocal
> > > Segmentation fault
> 
> Apparently it's a signedness problem...
[...]
> Which can be "fixed" with...
> 
> --- tai64nlocal.c~      2013-09-12 04:56:24.145298692 -0400
> +++ tai64nlocal.c       2013-09-12 04:56:47.576278760 -0400
> @@ -52,6 +52,7 @@
>          nanosecs += u;
>        }
>        secs -= 4611686018427387914ULL;
> +      secs = secs > 0 ? secs : 0;
>        t = localtime(&secs);
>        out(num,fmt_ulong(num,1900 + t->tm_year));
>        out("-",1); out(num,fmt_uint0(num,1 + t->tm_mon,2));
> 
> 
> Resulting in...
> 
> $ echo @ | tai64nlocal
> 1969-12-31 19:00:00.000000000

For what it's worth, this appears to be the same issue that Jeremy Fishman
reported in
<CAD7zAcs--iyq1cq2-muBHMA6KTPR4rUUN8SRG0bwcTFwRk49tw@mail.gmail.com> last
November.  He'll be happy for the fix ;)

Charles
-- 
-----------------------------------------------------------------------
Charles Cazabon
GPL'ed software available at:               http://pyropus.ca/software/
-----------------------------------------------------------------------