From: Takashi Iwai Date: Wed, 11 Mar 2020 09:17:39 +0000 (+0100) Subject: ssb: Use scnprintf() for avoiding potential buffer overflow X-Git-Tag: v5.15~4200^2~86^2~27 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ca44e47a2b8611178d38d4ed9532f793cf4244a8;p=platform%2Fkernel%2Flinux-starfive.git ssb: 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 Signed-off-by: Kalle Valo --- diff --git a/drivers/ssb/sprom.c b/drivers/ssb/sprom.c index 4f028a8..52d2e0f 100644 --- a/drivers/ssb/sprom.c +++ b/drivers/ssb/sprom.c @@ -26,9 +26,9 @@ static int sprom2hex(const u16 *sprom, char *buf, size_t buf_len, int i, pos = 0; for (i = 0; i < sprom_size_words; i++) - pos += snprintf(buf + pos, buf_len - pos - 1, + pos += scnprintf(buf + pos, buf_len - pos - 1, "%04X", swab16(sprom[i]) & 0xFFFF); - pos += snprintf(buf + pos, buf_len - pos - 1, "\n"); + pos += scnprintf(buf + pos, buf_len - pos - 1, "\n"); return pos + 1; }