]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
rtc: fix snprintf() checking in is_rtc_hctosys()
authorDan Carpenter <dan.carpenter@oracle.com>
Tue, 11 May 2021 07:19:26 +0000 (10:19 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 20 Jul 2021 14:05:55 +0000 (16:05 +0200)
commitab4d76eb77371af83f8272fbe05bee8154756d0a
treece4c41f1c5ed0021c108fb95d4ee5d29fe899e8b
parente352463654037ddade0987b2f5ab2cc87e80c81f
rtc: fix snprintf() checking in is_rtc_hctosys()

[ Upstream commit 54b909436ede47e0ee07f1765da27ec2efa41e84 ]

The scnprintf() function silently truncates the printf() and returns
the number bytes that it was able to copy (not counting the NUL
terminator).  Thus, the highest value it can return here is
"NAME_SIZE - 1" and the overflow check is dead code.  Fix this by
using the snprintf() function which returns the number of bytes that
would have been copied if there was enough space and changing the
condition from "> NAME_SIZE" to ">= NAME_SIZE".

Fixes: 92589c986b33 ("rtc-proc: permit the /proc/driver/rtc device to use other devices")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/YJov/pcGmhLi2pEl@mwanda
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/rtc/proc.c