[PATCH] video/hdmi: prefer strlcpy to strncpy

Subsystems: framebuffer layer, the rest

STALE2999d

2 messages, 1 author, 2018-05-30 · open the first message on its own page

[PATCH] video/hdmi: prefer strlcpy to strncpy

From: Nick Desaulniers <hidden>
Date: 2018-05-29 06:59:16

Fixes a stringop-truncation warning from gcc-8.

Signed-off-by: Nick Desaulniers <redacted>
---
 drivers/video/hdmi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/video/hdmi.c b/drivers/video/hdmi.c
index 111a0ab..46c184c 100644
--- a/drivers/video/hdmi.c
+++ b/drivers/video/hdmi.c
@@ -168,8 +168,8 @@ int hdmi_spd_infoframe_init(struct hdmi_spd_infoframe *frame,
 	frame->version = 1;
 	frame->length = HDMI_SPD_INFOFRAME_SIZE;
 
-	strncpy(frame->vendor, vendor, sizeof(frame->vendor));
-	strncpy(frame->product, product, sizeof(frame->product));
+	strlcpy(frame->vendor, vendor, sizeof(frame->vendor));
+	strlcpy(frame->product, product, sizeof(frame->product));
 
 	return 0;
 }
-- 
2.7.4

Re: [PATCH] video/hdmi: prefer strlcpy to strncpy

From: Nick Desaulniers <hidden>
Date: 2018-05-30 01:58:44

On Mon, May 28, 2018 at 11:59 PM, Nick Desaulniers
[off-list ref] wrote:
quoted hunk
Fixes a stringop-truncation warning from gcc-8.

Signed-off-by: Nick Desaulniers <redacted>
---
 drivers/video/hdmi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/video/hdmi.c b/drivers/video/hdmi.c
index 111a0ab..46c184c 100644
--- a/drivers/video/hdmi.c
+++ b/drivers/video/hdmi.c
@@ -168,8 +168,8 @@ int hdmi_spd_infoframe_init(struct hdmi_spd_infoframe *frame,
        frame->version = 1;
        frame->length = HDMI_SPD_INFOFRAME_SIZE;

-       strncpy(frame->vendor, vendor, sizeof(frame->vendor));
-       strncpy(frame->product, product, sizeof(frame->product));
+       strlcpy(frame->vendor, vendor, sizeof(frame->vendor));
+       strlcpy(frame->product, product, sizeof(frame->product));

        return 0;
 }
--
2.7.4
Eric points out this can leak kernel memory if size is less than length of src.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help