From: Thomas Zimmermann <tzimmermann@suse.de> To: Sam Ravnborg <sam@ravnborg.org> Cc: b.zolnierkie@samsung.com, gwan-gyeong.mun@intel.com, daniel.vetter@ffwll.ch, bernard@vivo.com, laurent.pinchart@ideasonboard.com, linux-fbdev@vger.kernel.org, dri-devel@lists.freedesktop.org Subject: Re: [PATCH] drivers/video: Fix -Wstringop-truncation in hdmi.c Date: Sun, 1 Nov 2020 17:43:55 +0100 [thread overview] Message-ID: <acbbfe44-4fdb-2c9f-2583-aebf5941d83b@suse.de> (raw) In-Reply-To: <20201101095021.GE1166694@ravnborg.org> [-- Attachment #1.1.1: Type: text/plain, Size: 2726 bytes --] Hi Am 01.11.20 um 10:50 schrieb Sam Ravnborg: > On Wed, Oct 21, 2020 at 02:12:41PM +0200, Thomas Zimmermann wrote: >> Trying to copy into the string fields with strncpy() gives a warning from >> gcc. Both fields are part of a packed HDMI header and do not require a >> terminating \0 character. >> >> ../drivers/video/hdmi.c: In function 'hdmi_spd_infoframe_init': >> ../drivers/video/hdmi.c:230:2: warning: 'strncpy' specified bound 8 equals destination size [-Wstringop-truncation] >> 230 | strncpy(frame->vendor, vendor, sizeof(frame->vendor)); >> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >> ../drivers/video/hdmi.c:231:2: warning: 'strncpy' specified bound 16 equals destination size [-Wstringop-truncation] >> 231 | strncpy(frame->product, product, sizeof(frame->product)); >> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >> >> Just use memcpy() instead. >> >> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de> > I assume vendor is guaranteed to be 0-termindated. It's a fixed-length field in the protocol. There's similar code in radeon IIRC. So it would be nice to disable the warning in these cases. But that's probably to much fiddling. > Reviewed-by: Sam Ravnborg <sam@ravnborg.org> Thanks. Best regards Thomas > >> --- >> drivers/video/hdmi.c | 8 ++++++-- >> 1 file changed, 6 insertions(+), 2 deletions(-) >> >> diff --git a/drivers/video/hdmi.c b/drivers/video/hdmi.c >> index b7a1d6fae90d..1e4cb63d0d11 100644 >> --- a/drivers/video/hdmi.c >> +++ b/drivers/video/hdmi.c >> @@ -221,14 +221,18 @@ EXPORT_SYMBOL(hdmi_avi_infoframe_pack); >> int hdmi_spd_infoframe_init(struct hdmi_spd_infoframe *frame, >> const char *vendor, const char *product) >> { >> + size_t len; >> + >> memset(frame, 0, sizeof(*frame)); >> >> frame->type = HDMI_INFOFRAME_TYPE_SPD; >> frame->version = 1; >> frame->length = HDMI_SPD_INFOFRAME_SIZE; >> >> - strncpy(frame->vendor, vendor, sizeof(frame->vendor)); >> - strncpy(frame->product, product, sizeof(frame->product)); >> + len = strlen(vendor); >> + memcpy(frame->vendor, vendor, min(len, sizeof(frame->vendor))); >> + len = strlen(product); >> + memcpy(frame->product, product, min(len, sizeof(frame->product))); >> >> return 0; >> } >> -- >> 2.28.0 >> >> _______________________________________________ >> dri-devel mailing list >> dri-devel@lists.freedesktop.org >> https://lists.freedesktop.org/mailman/listinfo/dri-devel -- Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix Imendörffer [-- Attachment #1.1.2: OpenPGP_0x680DC11D530B7A23.asc --] [-- Type: application/pgp-keys, Size: 4259 bytes --] [-- Attachment #2: OpenPGP digital signature --] [-- Type: application/pgp-signature, Size: 495 bytes --]
WARNING: multiple messages have this Message-ID (diff)
From: Thomas Zimmermann <tzimmermann@suse.de> To: Sam Ravnborg <sam@ravnborg.org> Cc: linux-fbdev@vger.kernel.org, b.zolnierkie@samsung.com, bernard@vivo.com, dri-devel@lists.freedesktop.org, gwan-gyeong.mun@intel.com, laurent.pinchart@ideasonboard.com, daniel.vetter@ffwll.ch Subject: Re: [PATCH] drivers/video: Fix -Wstringop-truncation in hdmi.c Date: Sun, 1 Nov 2020 17:43:55 +0100 [thread overview] Message-ID: <acbbfe44-4fdb-2c9f-2583-aebf5941d83b@suse.de> (raw) In-Reply-To: <20201101095021.GE1166694@ravnborg.org> [-- Attachment #1.1.1.1: Type: text/plain, Size: 2726 bytes --] Hi Am 01.11.20 um 10:50 schrieb Sam Ravnborg: > On Wed, Oct 21, 2020 at 02:12:41PM +0200, Thomas Zimmermann wrote: >> Trying to copy into the string fields with strncpy() gives a warning from >> gcc. Both fields are part of a packed HDMI header and do not require a >> terminating \0 character. >> >> ../drivers/video/hdmi.c: In function 'hdmi_spd_infoframe_init': >> ../drivers/video/hdmi.c:230:2: warning: 'strncpy' specified bound 8 equals destination size [-Wstringop-truncation] >> 230 | strncpy(frame->vendor, vendor, sizeof(frame->vendor)); >> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >> ../drivers/video/hdmi.c:231:2: warning: 'strncpy' specified bound 16 equals destination size [-Wstringop-truncation] >> 231 | strncpy(frame->product, product, sizeof(frame->product)); >> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >> >> Just use memcpy() instead. >> >> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de> > I assume vendor is guaranteed to be 0-termindated. It's a fixed-length field in the protocol. There's similar code in radeon IIRC. So it would be nice to disable the warning in these cases. But that's probably to much fiddling. > Reviewed-by: Sam Ravnborg <sam@ravnborg.org> Thanks. Best regards Thomas > >> --- >> drivers/video/hdmi.c | 8 ++++++-- >> 1 file changed, 6 insertions(+), 2 deletions(-) >> >> diff --git a/drivers/video/hdmi.c b/drivers/video/hdmi.c >> index b7a1d6fae90d..1e4cb63d0d11 100644 >> --- a/drivers/video/hdmi.c >> +++ b/drivers/video/hdmi.c >> @@ -221,14 +221,18 @@ EXPORT_SYMBOL(hdmi_avi_infoframe_pack); >> int hdmi_spd_infoframe_init(struct hdmi_spd_infoframe *frame, >> const char *vendor, const char *product) >> { >> + size_t len; >> + >> memset(frame, 0, sizeof(*frame)); >> >> frame->type = HDMI_INFOFRAME_TYPE_SPD; >> frame->version = 1; >> frame->length = HDMI_SPD_INFOFRAME_SIZE; >> >> - strncpy(frame->vendor, vendor, sizeof(frame->vendor)); >> - strncpy(frame->product, product, sizeof(frame->product)); >> + len = strlen(vendor); >> + memcpy(frame->vendor, vendor, min(len, sizeof(frame->vendor))); >> + len = strlen(product); >> + memcpy(frame->product, product, min(len, sizeof(frame->product))); >> >> return 0; >> } >> -- >> 2.28.0 >> >> _______________________________________________ >> dri-devel mailing list >> dri-devel@lists.freedesktop.org >> https://lists.freedesktop.org/mailman/listinfo/dri-devel -- Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix Imendörffer [-- Attachment #1.1.1.2: OpenPGP_0x680DC11D530B7A23.asc --] [-- Type: application/pgp-keys, Size: 4259 bytes --] [-- Attachment #1.2: OpenPGP digital signature --] [-- Type: application/pgp-signature, Size: 495 bytes --] [-- Attachment #2: Type: text/plain, Size: 160 bytes --] _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2020-11-01 16:44 UTC|newest] Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-10-21 12:12 [PATCH] drivers/video: Fix -Wstringop-truncation in hdmi.c Thomas Zimmermann 2020-10-21 12:12 ` Thomas Zimmermann 2020-10-21 23:06 ` Laurent Pinchart 2020-10-21 23:06 ` Laurent Pinchart 2020-10-22 7:01 ` Thomas Zimmermann 2020-10-22 7:01 ` Thomas Zimmermann 2020-11-01 9:50 ` Sam Ravnborg 2020-11-01 9:50 ` Sam Ravnborg 2020-11-01 16:43 ` Thomas Zimmermann [this message] 2020-11-01 16:43 ` Thomas Zimmermann
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=acbbfe44-4fdb-2c9f-2583-aebf5941d83b@suse.de \ --to=tzimmermann@suse.de \ --cc=b.zolnierkie@samsung.com \ --cc=bernard@vivo.com \ --cc=daniel.vetter@ffwll.ch \ --cc=dri-devel@lists.freedesktop.org \ --cc=gwan-gyeong.mun@intel.com \ --cc=laurent.pinchart@ideasonboard.com \ --cc=linux-fbdev@vger.kernel.org \ --cc=sam@ravnborg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.