]> git.baikalelectronics.ru Git - kernel.git/commit
rtc: Fix UBSAN overflow warning
authorZhangXiaoxu <zhangxiaoxu5@huawei.com>
Thu, 20 Dec 2018 09:36:56 +0000 (17:36 +0800)
committerAlexandre Belloni <alexandre.belloni@bootlin.com>
Thu, 10 Jan 2019 21:02:44 +0000 (22:02 +0100)
commitcd06c5223a71d515f6eb9c5b63e21601879c6a22
treef28558c2770740be30cdc607b1b5ca21a021c2e9
parentcc59c7008f15960e2ed289fdd4e5574cf0e10c32
rtc: Fix UBSAN overflow warning

Users may call 'ioctl' and pass a very big value on 'tm->tm_year'.
It can be overflowed in 'int' after add 1900.
In function 'rtc_month_days' and 'mktime64', also treated it as an
'unsigned' parameter.

UBSAN: Undefined behaviour in drivers/rtc/rtc-lib.c:103:59
signed integer overflow:
2147483647 + 1900 cannot be represented in type 'int'

UBSAN: Undefined behaviour in drivers/rtc/rtc-lib.c:119:30
signed integer overflow:
2147483647 + 1900 cannot be represented in type 'int'

So, covert it to 'unsigned' explicitly.

Signed-off-by: ZhangXiaoxu <zhangxiaoxu5@huawei.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
drivers/rtc/lib.c