From: Laurent Vivier <laurent@vivier.eu>
To: "Daniel P. Berrangé" <berrange@redhat.com>
Cc: Alistair Francis <Alistair.Francis@wdc.com>,
"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>,
"alistair23@gmail.com" <alistair23@gmail.com>,
"kraxel@redhat.com" <kraxel@redhat.com>,
"riku.voipio@iki.fi" <riku.voipio@iki.fi>,
"qemu-trivial@nongnu.org" <qemu-trivial@nongnu.org>
Subject: Re: [Qemu-devel] [PATCH v2 4/5] linux-user/uname: Fix GCC 9 build warnings
Date: Wed, 1 May 2019 11:46:07 +0200 [thread overview]
Message-ID: <aad5f010-75c5-9b45-b830-3719cec77b9d@vivier.eu> (raw)
In-Reply-To: <20190501094452.GQ29808@redhat.com>
On 01/05/2019 11:44, Daniel P. Berrangé wrote:
> On Wed, May 01, 2019 at 11:40:13AM +0200, Laurent Vivier wrote:
>> On 01/05/2019 01:28, Alistair Francis wrote:
>>> Fix this warning when building with GCC9 on Fedora 30:
>>> In function ‘strncpy’,
>>> inlined from ‘sys_uname’ at /home/alistair/qemu/linux-user/uname.c:94:3:
>>> /usr/include/bits/string_fortified.h:106:10: error: ‘__builtin_strncpy’ output may be truncated copying 64 bytes from a string of length 64 [-Werror=stringop-truncation]
>>> 106 | return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
>>> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>>
>>> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
>>> ---
>>> linux-user/uname.c | 2 +-
>>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/linux-user/uname.c b/linux-user/uname.c
>>> index 313b79dbad..2fc6096a5b 100644
>>> --- a/linux-user/uname.c
>>> +++ b/linux-user/uname.c
>>> @@ -73,7 +73,7 @@ const char *cpu_to_uname_machine(void *cpu_env)
>>> #define COPY_UTSNAME_FIELD(dest, src) \
>>> do { \
>>> /* __NEW_UTS_LEN doesn't include terminating null */ \
>>> - (void) strncpy((dest), (src), __NEW_UTS_LEN); \
>>> + (void) memcpy((dest), (src), MIN(strlen(src), __NEW_UTS_LEN)); \
>>
>> You should use MIN(strlen(src) + 1, __NEW_UTS_LEN) to copy the NUL
>> character if it is present and fit in __NEW_UTS_LEN.
>
> IMHO we shouldn't use strlen at all. I proposed fixing it using sizeof()
> instead here:
>
> https://lists.gnu.org/archive/html/qemu-devel/2019-04/msg02154.html
>
Yes, it's better.
Thanks,
Laurent
WARNING: multiple messages have this Message-ID (diff)
From: Laurent Vivier <laurent@vivier.eu>
To: "Daniel P. Berrangé" <berrange@redhat.com>
Cc: "qemu-trivial@nongnu.org" <qemu-trivial@nongnu.org>,
"riku.voipio@iki.fi" <riku.voipio@iki.fi>,
"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>,
Alistair Francis <Alistair.Francis@wdc.com>,
"kraxel@redhat.com" <kraxel@redhat.com>,
"alistair23@gmail.com" <alistair23@gmail.com>
Subject: Re: [Qemu-devel] [PATCH v2 4/5] linux-user/uname: Fix GCC 9 build warnings
Date: Wed, 1 May 2019 11:46:07 +0200 [thread overview]
Message-ID: <aad5f010-75c5-9b45-b830-3719cec77b9d@vivier.eu> (raw)
Message-ID: <20190501094607.-VnFb7C07ow9Ulw2fGDh-GpKfgGOTxTCNdbow_Izqpo@z> (raw)
In-Reply-To: <20190501094452.GQ29808@redhat.com>
On 01/05/2019 11:44, Daniel P. Berrangé wrote:
> On Wed, May 01, 2019 at 11:40:13AM +0200, Laurent Vivier wrote:
>> On 01/05/2019 01:28, Alistair Francis wrote:
>>> Fix this warning when building with GCC9 on Fedora 30:
>>> In function ‘strncpy’,
>>> inlined from ‘sys_uname’ at /home/alistair/qemu/linux-user/uname.c:94:3:
>>> /usr/include/bits/string_fortified.h:106:10: error: ‘__builtin_strncpy’ output may be truncated copying 64 bytes from a string of length 64 [-Werror=stringop-truncation]
>>> 106 | return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
>>> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>>
>>> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
>>> ---
>>> linux-user/uname.c | 2 +-
>>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/linux-user/uname.c b/linux-user/uname.c
>>> index 313b79dbad..2fc6096a5b 100644
>>> --- a/linux-user/uname.c
>>> +++ b/linux-user/uname.c
>>> @@ -73,7 +73,7 @@ const char *cpu_to_uname_machine(void *cpu_env)
>>> #define COPY_UTSNAME_FIELD(dest, src) \
>>> do { \
>>> /* __NEW_UTS_LEN doesn't include terminating null */ \
>>> - (void) strncpy((dest), (src), __NEW_UTS_LEN); \
>>> + (void) memcpy((dest), (src), MIN(strlen(src), __NEW_UTS_LEN)); \
>>
>> You should use MIN(strlen(src) + 1, __NEW_UTS_LEN) to copy the NUL
>> character if it is present and fit in __NEW_UTS_LEN.
>
> IMHO we shouldn't use strlen at all. I proposed fixing it using sizeof()
> instead here:
>
> https://lists.gnu.org/archive/html/qemu-devel/2019-04/msg02154.html
>
Yes, it's better.
Thanks,
Laurent
next prev parent reply other threads:[~2019-05-01 9:46 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-30 23:28 [Qemu-devel] [PATCH v2 0/5] Fix some GCC 9 build warnings Alistair Francis
2019-04-30 23:28 ` Alistair Francis
2019-04-30 23:28 ` [Qemu-devel] [PATCH v2 1/5] util/qemu-sockets: Fix " Alistair Francis
2019-04-30 23:28 ` Alistair Francis
2019-05-01 9:35 ` Laurent Vivier
2019-05-01 9:35 ` Laurent Vivier
2019-05-01 9:41 ` Daniel P. Berrangé
2019-05-01 9:41 ` Daniel P. Berrangé
2019-05-02 17:57 ` Alistair Francis
2019-05-02 17:57 ` Alistair Francis
2019-04-30 23:28 ` [Qemu-devel] [PATCH v2 2/5] hw/usb/hcd-xhci: Fix GCC 9 build warning Alistair Francis
2019-04-30 23:28 ` Alistair Francis
2019-05-01 9:37 ` Laurent Vivier
2019-05-01 9:37 ` Laurent Vivier
2019-05-01 9:43 ` Daniel P. Berrangé
2019-05-01 9:43 ` Daniel P. Berrangé
2019-05-01 14:12 ` Richard Henderson
2019-05-01 14:12 ` Richard Henderson
2019-05-01 15:21 ` Philippe Mathieu-Daudé
2019-05-01 15:21 ` Philippe Mathieu-Daudé
2019-05-02 17:53 ` Alistair Francis
2019-05-02 17:53 ` Alistair Francis
2019-04-30 23:28 ` [Qemu-devel] [PATCH v2 3/5] hw/usb/dev-mtp: " Alistair Francis
2019-04-30 23:28 ` Alistair Francis
2019-05-01 7:12 ` Thomas Huth
2019-05-01 7:12 ` Thomas Huth
2019-05-01 9:40 ` Daniel P. Berrangé
2019-05-01 9:40 ` Daniel P. Berrangé
2019-05-02 17:48 ` Alistair Francis
2019-05-02 17:48 ` Alistair Francis
2019-04-30 23:28 ` [Qemu-devel] [PATCH v2 4/5] linux-user/uname: Fix GCC 9 build warnings Alistair Francis
2019-04-30 23:28 ` Alistair Francis
2019-05-01 9:40 ` Laurent Vivier
2019-05-01 9:40 ` Laurent Vivier
2019-05-01 9:44 ` Daniel P. Berrangé
2019-05-01 9:44 ` Daniel P. Berrangé
2019-05-01 9:46 ` Laurent Vivier [this message]
2019-05-01 9:46 ` Laurent Vivier
2019-05-01 12:00 ` Eric Blake
2019-05-01 12:00 ` Eric Blake
2019-05-02 17:24 ` Alistair Francis
2019-05-02 17:24 ` Alistair Francis
2019-04-30 23:29 ` [Qemu-devel] [PATCH v2 5/5] linux-user/elfload: " Alistair Francis
2019-04-30 23:29 ` Alistair Francis
2019-05-01 9:40 ` Laurent Vivier
2019-05-01 9:40 ` Laurent Vivier
2019-05-01 14:15 ` Richard Henderson
2019-05-01 14:15 ` Richard Henderson
2019-05-02 8:14 ` Laurent Vivier
2019-05-02 8:14 ` Laurent Vivier
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=aad5f010-75c5-9b45-b830-3719cec77b9d@vivier.eu \
--to=laurent@vivier.eu \
--cc=Alistair.Francis@wdc.com \
--cc=alistair23@gmail.com \
--cc=berrange@redhat.com \
--cc=kraxel@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-trivial@nongnu.org \
--cc=riku.voipio@iki.fi \
/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: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).