HID: hid-picolcd_fb: Use scnprintf() for avoiding potential buffer overflow
Subsystems (2)
PATCH 1/1 HID: hid-picolcd_fb: Use scnprintf() for avoiding potential buffer overflow
Since snprintf() returns the would-be-output size instead of the actual output size, the succeeding calls may go beyond the given buffer limit. Fix it by replacing with scnprintf().
Signed-off-by Takashi Iwai <[email protected]>
--- drivers/hid/hid-picolcd_fb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/hid/hid-picolcd_fb.c +2 -2
@@ -458,9 +458,9 @@ static ssize_t picolcd_fb_update_rate_show(struct device *dev,if (ret >=PAGE_SIZE )break ;else if (i == fb_update_rate) - ret +=snprintf (buf+ret,PAGE_SIZE -ret,"[%u] " , i); + ret +=scnprintf (buf+ret,PAGE_SIZE -ret,"[%u] " , i);else - ret +=snprintf (buf+ret,PAGE_SIZE -ret,"%u " , i); + ret +=scnprintf (buf+ret,PAGE_SIZE -ret,"%u " , i);if (ret >0 ) buf[min (ret, (size_t )PAGE_SIZE )-1 ] ='\n' ;return ret;
Signature · 1 line
2.16.4
Quoted 5 lines · Takashi Iwai
Since
snprintf()returns the would-be-output size instead of the actual output size, the succeeding calls may go beyond the given buffer limit. Fix it by replacing withscnprintf().Signed-off-by Takashi Iwai <[email protected]>
Applied to for-5.6/upstream-fixes. Thanks,
Signature · 2 lines
Jiri Kosina SUSE Labs