|
|
Message-ID: <CAH8yC8nhxhRcgB-v8K-nose_ASL3DxhgmnaqKnjfEwukEhRR1Q@mail.gmail.com>
Date: Wed, 25 Nov 2026 14:59:19 -0500
From: Jeffrey Walton <noloader@...il.com>
To: Rich Felker <dalias@...c.org>
Cc: musl@...ts.openwall.com, 吴尚哲 <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 2:55 PM Rich Felker <dalias@...c.org> wrote:
> On Wed, Nov 25, 2026 at 02:29:47PM -0500, Jeffrey Walton wrote:
> > 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.
>
> Return it to whom? The invalid value was not passed by the
> application. It's obtained from the environment and used ambiently in
> functions that process local times.
>
This seems like a design flaw -- assuming a function can never fail.
> > 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.
>
> That seems like a weird choice. If trying to accept it, mod 12 would
> probably make more sense.
Ah, right. At least for the 24-hour clock.
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.