|
|
Message-ID: <20261125200355.GU5716@brightrain.aerifal.cx> Date: Wed, 25 Nov 2026 15:03:55 -0500 From: Rich Felker <dalias@...c.org> To: Jeffrey Walton <noloader@...il.com> 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 02:59:19PM -0500, Jeffrey Walton wrote: > 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 don't think having time functions fail in a way outside the control of the application (note: it's not safe to set env vars for yourself) because the user/invoking process set TZ to something invalid is at all helpful. Most of these functions *can* fail, but having them always fail in a way the application can't fix seems like a very bad choice even if it would be allowed. > > > 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. These are months not hours. Rich
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.