Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAH8yC8=EmHzSBrFZct+RbNx4L7SSkbPNwZOrqn5Njhsa_zDRiQ@mail.gmail.com>
Date: Wed, 25 Nov 2026 14:29:47 -0500
From: Jeffrey Walton <noloader@...il.com>
To: musl@...ts.openwall.com
Cc: 吴尚哲 <wushangzhe26@....pku.edu.cn>
Subject: Re: Bug in TZ rule handling: out-of-bounds read for an invalid month

On Wed, Nov 25, 2026 at 1:07 PM Rich Felker <dalias@...c.org> wrote:

> On Thu, Nov 26, 2026 at 01:43:24AM +0800, 吴尚哲 wrote:
> > Hello,
> > We found a bug in musl 1.2.5 on x86_64: when the month in an
> > Mm.n.d daylight-saving rule is out of range, localtime_r() can
> > read outside the bounds of a month lookup table.
> >
> >
> > In src/time/__tz.c:347, rule_to_secs() calls:
> >     t += __month_to_secs(m-1, is_leap);
> >
> >
> > Because m is not checked against the valid range of 1 through 12,
> > m-1 can be outside the bounds of the 12-element table that
> > __month_to_secs() indexes in src/time/__month_to_secs.c.
>
> I suppose we need to decide what should happen on invalid TZ strings.
> POSIX specifies:
>
>     "The application shall ensure that the value of TZ is in one of
>     the three formats (spaces inserted for clarity):
>
>     ..."
>
> So there isn't a constraint on implementations as to what they should
> do when it's invalid.
>
> I suppose we can make it ignore them and give UTC. Any objections to
> that?


I think the principle of least surprise would say to return an error on an
invalid parameter.  I don't think it is wise to return something to the
user that appears valid when faced with an invalid parameter.

I suppose Musl could document it clamps values to the range [1,12], and
anything less than 1 is clamped to 1, and anything greater than 12 is
clamped to 12.

Jeff

Content of type "text/html" skipped

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.