From: "Philippe Mathieu-Daudé" <f4bug@amsat.org>
To: "qemu-devel@nongnu.org Developers" <qemu-devel@nongnu.org>
Cc: Luc Michel <luc@lmichel.fr>,
Alistair Francis <alistair.francis@wdc.com>,
Eduardo Habkost <ehabkost@redhat.com>,
Richard Henderson <rth@twiddle.net>
Subject: Re: [PATCH-for-5.2] util/cutils: Silent Coverity array overrun warning in freq_to_str()
Date: Thu, 29 Oct 2020 19:56:50 +0100 [thread overview]
Message-ID: <CAAdtpL4-qCoUXMXCuS-GXQJO_ab--dWSDqgdcfZMdjSptHQwxQ@mail.gmail.com> (raw)
In-Reply-To: <20201029185506.1241912-1-f4bug@amsat.org>
Patch aiming the 5.2 release.
On Thu, Oct 29, 2020 at 7:55 PM Philippe Mathieu-Daudé <f4bug@amsat.org> wrote:
>
> The biggest input value freq_to_str() can accept is UINT64_MAX,
> which is ~18.446 EHz, less than 1000 EHz.
> Add an assertion to help Coverity.
>
> This silents CID 1435957: Memory - illegal accesses (OVERRUN):
>
> >>> Overrunning array "suffixes" of 7 8-byte elements at element
> index 7 (byte offset 63) using index "idx" (which evaluates to 7).
>
> Reported-by: Eduardo Habkost <ehabkost@redhat.com>
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
> util/cutils.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/util/cutils.c b/util/cutils.c
> index c395974fab4..69c0ad7f888 100644
> --- a/util/cutils.c
> +++ b/util/cutils.c
> @@ -891,6 +891,7 @@ char *freq_to_str(uint64_t freq_hz)
> double freq = freq_hz;
> size_t idx = 0;
>
> + assert(freq <= UINT64_MAX); /* Max 64-bit value is less than 1000 EHz */
> while (freq >= 1000.0 && idx < ARRAY_SIZE(suffixes)) {
> freq /= 1000.0;
> idx++;
> --
> 2.26.2
>
next prev parent reply other threads:[~2020-10-29 18:59 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-29 18:55 [PATCH] util/cutils: Silent Coverity array overrun warning in freq_to_str() Philippe Mathieu-Daudé
2020-10-29 18:56 ` Philippe Mathieu-Daudé [this message]
2020-10-29 19:13 ` Peter Maydell
2020-10-29 19:16 ` Peter Maydell
2020-10-29 20:40 ` Eduardo Habkost
2020-10-29 20:26 ` Eduardo Habkost
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=CAAdtpL4-qCoUXMXCuS-GXQJO_ab--dWSDqgdcfZMdjSptHQwxQ@mail.gmail.com \
--to=f4bug@amsat.org \
--cc=alistair.francis@wdc.com \
--cc=ehabkost@redhat.com \
--cc=luc@lmichel.fr \
--cc=qemu-devel@nongnu.org \
--cc=rth@twiddle.net \
/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).