From: David Laight <David.Laight@ACULAB.COM>
To: 'Dan Carpenter' <dan.carpenter@linaro.org>,
Linke Li <lilinke99@foxmail.com>
Cc: "linux-fsdevel@vger.kernel.org" <linux-fsdevel@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Jan Kara <jack@suse.cz>, Linke Li <lilinke99@gmail.com>
Subject: RE: [PATCH] isofs: fix undefined behavior in iso_date()
Date: Thu, 13 Jul 2023 14:11:02 +0000 [thread overview]
Message-ID: <aa811b76ac704140bfa98884c8d6f51e@AcuMS.aculab.com> (raw)
In-Reply-To: <79582844-3178-451c-822e-a692bfd27e9c@moroto.mountain>
From: Dan Carpenter
> Sent: 10 July 2023 10:57
>
> It looks like maybe there is an issue with "year" as well.
>
> fs/isofs/util.c
> 19 int iso_date(u8 *p, int flag)
> 20 {
> 21 int year, month, day, hour, minute, second, tz;
> 22 int crtime;
> 23
> 24 year = p[0];
> ^^^^^
> year is 0-255.
....
> 32
> 33 if (year < 0) {
> ^^^^^^^^
> But this checks year for < 0 which is impossible. Should it be:
>
> year = (signed char)p[0];?
Or not?
What happens in 2027 ?
I bet the value has to be treated an unsigned.
>
> 34 crtime = 0;
> 35 } else {
> 36 crtime = mktime64(year+1900, month, day, hour, minute, second);
> 37
> 38 /* sign extend */
> 39 if (tz & 0x80)
> 40 tz |= (-1 << 8);
Just change the definition of tz from 'int' to 's8'
and it will all happen 'by magic'.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
next prev parent reply other threads:[~2023-07-13 14:11 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-09 6:42 Linke Li
2023-07-09 11:41 ` Matthew Wilcox
2023-07-13 7:22 ` linke li
[not found] ` <63c6f039-4b33-cdfc-1e49-fc9fc35d513e@web.de>
2023-07-10 6:10 ` linke li
2023-07-10 9:56 ` Dan Carpenter
2023-07-13 14:11 ` David Laight [this message]
2023-07-13 14:26 ` Dan Carpenter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aa811b76ac704140bfa98884c8d6f51e@AcuMS.aculab.com \
--to=david.laight@aculab.com \
--cc=dan.carpenter@linaro.org \
--cc=jack@suse.cz \
--cc=lilinke99@foxmail.com \
--cc=lilinke99@gmail.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®