From: Eduardo Habkost <ehabkost@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
"Alistair Francis" <alistair.francis@wdc.com>,
"Luc Michel" <luc@lmichel.fr>,
"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
"Richard Henderson" <rth@twiddle.net>
Subject: [PATCH for-5.2] util/cutils: Fix bounds check at freq_to_str()
Date: Thu, 29 Oct 2020 16:38:50 -0400 [thread overview]
Message-ID: <20201029203850.434351-1-ehabkost@redhat.com> (raw)
Fix bounds check for idx at freq_to_str(), to actually ensure idx
never goes beyond the last element of the suffixes array.
Reported-by: Coverity (CID 1435957: OVERRUN)
Suggested-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
util/cutils.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/util/cutils.c b/util/cutils.c
index c395974fab..0d9261e1e5 100644
--- a/util/cutils.c
+++ b/util/cutils.c
@@ -891,7 +891,7 @@ char *freq_to_str(uint64_t freq_hz)
double freq = freq_hz;
size_t idx = 0;
- while (freq >= 1000.0 && idx < ARRAY_SIZE(suffixes)) {
+ while (freq >= 1000.0 && idx < ARRAY_SIZE(suffixes) - 1) {
freq /= 1000.0;
idx++;
}
--
2.28.0
next reply other threads:[~2020-10-29 20:40 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-29 20:38 Eduardo Habkost [this message]
2020-10-29 21:34 ` [PATCH for-5.2] util/cutils: Fix bounds check at freq_to_str() Philippe Mathieu-Daudé
2020-10-30 9:59 ` 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=20201029203850.434351-1-ehabkost@redhat.com \
--to=ehabkost@redhat.com \
--cc=alistair.francis@wdc.com \
--cc=f4bug@amsat.org \
--cc=luc@lmichel.fr \
--cc=peter.maydell@linaro.org \
--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).