* [PATCH] pinctrl: s32cc: Avoid possible string truncation
@ 2023-11-07 14:10 Chester Lin
2023-11-14 13:44 ` Linus Walleij
0 siblings, 1 reply; 2+ messages in thread
From: Chester Lin @ 2023-11-07 14:10 UTC (permalink / raw)
To: Chester Lin, NXP S32 Linux Team, Linus Walleij
Cc: linux-gpio, linux-kernel, kernel test robot
With "W=1" and "-Wformat-truncation" build options, the kernel test robot
found a possible string truncation warning in pinctrl-s32cc.c, which uses
an 8-byte char array to hold a memory region name "map%u". Since the
maximum number of digits that a u32 value can present is 10, and the "map"
string occupies 3 bytes with a termination '\0', which means the rest 4
bytes cannot fully present the integer "X" that exceeds 4 digits.
Here we check if the number >= 10000, which is the lowest value that
contains more than 4 digits.
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202311030159.iyUGjNGF-lkp@intel.com/
Signed-off-by: Chester Lin <clin@suse.com>
---
drivers/pinctrl/nxp/pinctrl-s32cc.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/pinctrl/nxp/pinctrl-s32cc.c b/drivers/pinctrl/nxp/pinctrl-s32cc.c
index 7daff9f186cd..7735d30f2be3 100644
--- a/drivers/pinctrl/nxp/pinctrl-s32cc.c
+++ b/drivers/pinctrl/nxp/pinctrl-s32cc.c
@@ -843,8 +843,8 @@ static int s32_pinctrl_probe_dt(struct platform_device *pdev,
if (!np)
return -ENODEV;
- if (mem_regions == 0) {
- dev_err(&pdev->dev, "mem_regions is 0\n");
+ if (mem_regions == 0 || mem_regions >= 10000) {
+ dev_err(&pdev->dev, "mem_regions is invalid: %u\n", mem_regions);
return -EINVAL;
}
--
2.40.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] pinctrl: s32cc: Avoid possible string truncation
2023-11-07 14:10 [PATCH] pinctrl: s32cc: Avoid possible string truncation Chester Lin
@ 2023-11-14 13:44 ` Linus Walleij
0 siblings, 0 replies; 2+ messages in thread
From: Linus Walleij @ 2023-11-14 13:44 UTC (permalink / raw)
To: Chester Lin
Cc: NXP S32 Linux Team, linux-gpio, linux-kernel, kernel test robot
On Tue, Nov 7, 2023 at 3:10 PM Chester Lin <clin@suse.com> wrote:
> With "W=1" and "-Wformat-truncation" build options, the kernel test robot
> found a possible string truncation warning in pinctrl-s32cc.c, which uses
> an 8-byte char array to hold a memory region name "map%u". Since the
> maximum number of digits that a u32 value can present is 10, and the "map"
> string occupies 3 bytes with a termination '\0', which means the rest 4
> bytes cannot fully present the integer "X" that exceeds 4 digits.
>
> Here we check if the number >= 10000, which is the lowest value that
> contains more than 4 digits.
>
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202311030159.iyUGjNGF-lkp@intel.com/
> Signed-off-by: Chester Lin <clin@suse.com>
Thanks for fixing this!
Patch applied for fixes.
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-11-14 13:44 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-07 14:10 [PATCH] pinctrl: s32cc: Avoid possible string truncation Chester Lin
2023-11-14 13:44 ` Linus Walleij
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®