From: Thomas Huth <thuth@redhat.com>
To: "Daniel P. Berrangé" <berrange@redhat.com>
Cc: Hyman Huang <yong.huang@smartx.com>, Peter Xu <peterx@redhat.com>,
Fabiano Rosas <farosas@suse.de>,
qemu-devel@nongnu.org
Subject: Re: [PATCH] migration/dirtyrate: Silence warning about strcpy() on OpenBSD
Date: Thu, 17 Oct 2024 07:39:58 +0200 [thread overview]
Message-ID: <32d9779e-d531-4451-af2c-c76e86f5b921@redhat.com> (raw)
In-Reply-To: <Zw_oM-RStF4QhWik@redhat.com>
On 16/10/2024 18.22, Daniel P. Berrangé wrote:
> On Wed, Oct 16, 2024 at 06:07:12PM +0200, Thomas Huth wrote:
>> The linker on OpenBSD complains:
>>
>> ld: warning: dirtyrate.c:447 (../src/migration/dirtyrate.c:447)(...):
>> warning: strcpy() is almost always misused, please use strlcpy()
>
> Is that the only place it complains ? We use 'strcpy' in almost
> 100 places across the codebase....
There are only a fistful of other warnings. I guess most of the spots are
turned into inlined code by the compiler, so the linker never sees those
other occurrences.
>> It's currently not a real problem in this case since both arrays
>> have the same size (256 bytes). But just in case somebody changes
>> the size of the source array in the future, let's better play safe
>> and use g_strlcpy() here instead.
>>
>> Signed-off-by: Thomas Huth <thuth@redhat.com>
>> ---
>> migration/dirtyrate.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c
>> index 233acb0855..090c76e934 100644
>> --- a/migration/dirtyrate.c
>> +++ b/migration/dirtyrate.c
>> @@ -444,7 +444,7 @@ static void get_ramblock_dirty_info(RAMBlock *block,
>> info->ramblock_pages = qemu_ram_get_used_length(block) >>
>> qemu_target_page_bits();
>> info->ramblock_addr = qemu_ram_get_host_addr(block);
>> - strcpy(info->idstr, qemu_ram_get_idstr(block));
>> + g_strlcpy(info->idstr, qemu_ram_get_idstr(block), sizeof(info->idstr));
>> }
>
> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
>
>
> Is it worth also adding
>
> G_STATIC_ASSERT(sizeof((struct RamblockDirtyInfo){}.idstr) ==
> sizeof((struct RAMBlock){}.idstr));
>
> at the top of this file, since both of these fields are expected to
> be the same size by this code, to avoid truncation.
... or alternatively check the return value of g_strlcpy() ? ... but that
wouldn't work if pstrcpy() if we switch to that function instead.
I don't mind either way - Peter, Fabiano, Hyman, what's your opinion here?
Thomas
next prev parent reply other threads:[~2024-10-17 5:41 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-16 16:07 [PATCH] migration/dirtyrate: Silence warning about strcpy() on OpenBSD Thomas Huth
2024-10-16 16:22 ` Daniel P. Berrangé
2024-10-16 17:09 ` Peter Xu
2024-10-17 5:39 ` Thomas Huth [this message]
2024-10-17 7:01 ` Yong Huang
2024-10-17 9:36 ` Peter Maydell
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=32d9779e-d531-4451-af2c-c76e86f5b921@redhat.com \
--to=thuth@redhat.com \
--cc=berrange@redhat.com \
--cc=farosas@suse.de \
--cc=peterx@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=yong.huang@smartx.com \
/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).