Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 5317797

Browse files
JustinStitthdeller
authored andcommitted
video: hdmi: prefer length specifier in format over string copying
strncpy() is deprecated for use on NUL-terminated destination strings [1] and as such we should prefer more robust and less ambiguous string interfaces. It looks like the main use of strncpy() here is to limit the amount of bytes printed from hdmi_log() by using a tmp buffer and limiting the number of bytes copied. Really, we should use the %.<len>s format qualifier to achieve this. Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1] Link: https://manpages.debian.org/testing/linux-manual-4.8/strscpy.9.en.html Link: KSPP/linux#90 Cc: linux-hardening@vger.kernel.org Signed-off-by: Justin Stitt <justinstitt@google.com> Reviewed-by: Kees Cook <keescook@chromium.org> Signed-off-by: Helge Deller <deller@gmx.de>
1 parent 91bcea4 commit 5317797

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

drivers/video/hdmi.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,17 +1310,11 @@ static void hdmi_spd_infoframe_log(const char *level,
13101310
struct device *dev,
13111311
const struct hdmi_spd_infoframe *frame)
13121312
{
1313-
u8 buf[17];
1314-
13151313
hdmi_infoframe_log_header(level, dev,
13161314
(const struct hdmi_any_infoframe *)frame);
13171315

1318-
memset(buf, 0, sizeof(buf));
1319-
1320-
strncpy(buf, frame->vendor, 8);
1321-
hdmi_log(" vendor: %s\n", buf);
1322-
strncpy(buf, frame->product, 16);
1323-
hdmi_log(" product: %s\n", buf);
1316+
hdmi_log(" vendor: %.8s\n", frame->vendor);
1317+
hdmi_log(" product: %.16s\n", frame->product);
13241318
hdmi_log(" source device information: %s (0x%x)\n",
13251319
hdmi_spd_sdi_get_name(frame->sdi), frame->sdi);
13261320
}

0 commit comments

Comments
 (0)