From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org,
Juan Quintela <quintela@redhat.com>, Fam Zheng <fam@euphon.net>,
Stefan Hajnoczi <stefanha@redhat.com>
Subject: Re: [PATCH 1/2] migration: Assert that migrate_multifd_compression() returns an in-range value
Date: Thu, 21 Jul 2022 13:02:49 +0100 [thread overview]
Message-ID: <YtlAaQ6QvFVdF826@work-vm> (raw)
In-Reply-To: <20220721115207.729615-2-peter.maydell@linaro.org>
* Peter Maydell (peter.maydell@linaro.org) wrote:
> Coverity complains that when we use the return value from
> migrate_multifd_compression() as an array index:
> multifd_recv_state->ops = multifd_ops[migrate_multifd_compression()];
>
> that this might overrun the array (which is declared to have size
> MULTIFD_COMPRESSION__MAX). This is because the function return type
> is MultiFDCompression, which is an autogenerated enum. The code
> generator includes the "one greater than the maximum possible value"
> MULTIFD_COMPRESSION__MAX in the enum, even though this is not
> actually a valid value for the enum, and this makes Coverity think
> that migrate_multifd_compression() could return that __MAX value and
> index off the end of the array.
>
> Suppress the Coverity error by asserting that the value we're going
> to return is within range.
>
> Resolves: Coverity CID 1487239, 1487254
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> ---
> migration/migration.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/migration/migration.c b/migration/migration.c
> index e03f698a3ca..befd4c58a69 100644
> --- a/migration/migration.c
> +++ b/migration/migration.c
> @@ -2617,6 +2617,7 @@ MultiFDCompression migrate_multifd_compression(void)
>
> s = migrate_get_current();
>
> + assert(s->parameters.multifd_compression < MULTIFD_COMPRESSION__MAX);
> return s->parameters.multifd_compression;
> }
>
> --
> 2.25.1
>
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
next prev parent reply other threads:[~2022-07-21 12:04 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-21 11:52 [PATCH 0/2] migration: fix coverity nits Peter Maydell
2022-07-21 11:52 ` [PATCH 1/2] migration: Assert that migrate_multifd_compression() returns an in-range value Peter Maydell
2022-07-21 12:02 ` Dr. David Alan Gilbert [this message]
2022-07-22 11:00 ` Juan Quintela
2022-07-21 11:52 ` [PATCH 2/2] migration: Define BLK_MIG_BLOCK_SIZE as unsigned long long Peter Maydell
2022-07-21 12:07 ` Dr. David Alan Gilbert
2022-07-21 12:44 ` Peter Maydell
2022-07-21 13:06 ` Dr. David Alan Gilbert
2022-07-22 12:47 ` Juan Quintela
2022-08-01 10:38 ` [PATCH 0/2] migration: fix coverity nits Peter Maydell
2022-08-02 13:49 ` Dr. David Alan Gilbert
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=YtlAaQ6QvFVdF826@work-vm \
--to=dgilbert@redhat.com \
--cc=fam@euphon.net \
--cc=peter.maydell@linaro.org \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
--cc=stefanha@redhat.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).