[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 6/9] util/cutils: Fix Coverity array overrun in freq_to_str()
From: |
Peter Maydell |
Subject: |
[PULL 6/9] util/cutils: Fix Coverity array overrun in freq_to_str() |
Date: |
Tue, 17 Nov 2020 13:48:31 +0000 |
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
Fix Coverity 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).
Note, the biggest input value freq_to_str() can accept is UINT64_MAX,
which is ~18.446 EHz, less than 1000 EHz.
Reported-by: Eduardo Habkost <ehabkost@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
Reviewed-by: Luc Michel <luc@lmichel.fr>
Message-id: 20201101215755.2021421-1-f4bug@amsat.org
Suggested-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
util/cutils.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/util/cutils.c b/util/cutils.c
index 9498e28e1a2..0b5073b3301 100644
--- a/util/cutils.c
+++ b/util/cutils.c
@@ -891,10 +891,11 @@ 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) {
freq /= 1000.0;
idx++;
}
+ assert(idx < ARRAY_SIZE(suffixes));
return g_strdup_printf("%0.3g %sHz", freq, suffixes[idx]);
}
--
2.20.1
- [PULL 0/9] target-arm queue, Peter Maydell, 2020/11/17
- [PULL 1/9] hw/arm/virt: ARM_VIRT must select ARM_GIC, Peter Maydell, 2020/11/17
- [PULL 2/9] exynos: Fix bad printf format specifiers, Peter Maydell, 2020/11/17
- [PULL 5/9] register: Remove unnecessary NULL check, Peter Maydell, 2020/11/17
- [PULL 4/9] target/openrisc: Remove dead code attempting to check "is timer disabled", Peter Maydell, 2020/11/17
- [PULL 3/9] hw/input/ps2.c: Remove remnants of printf debug, Peter Maydell, 2020/11/17
- [PULL 6/9] util/cutils: Fix Coverity array overrun in freq_to_str(),
Peter Maydell <=
- [PULL 8/9] hw/misc/tmp105: reset the T_low and T_High registers, Peter Maydell, 2020/11/17
- [PULL 9/9] tmp105: Correct handling of temperature limit checks, Peter Maydell, 2020/11/17
- [PULL 7/9] configure: Make "does libgio work" test pull in some actual functions, Peter Maydell, 2020/11/17
- Re: [PULL 0/9] target-arm queue, no-reply, 2020/11/17
- Re: [PULL 0/9] target-arm queue, Peter Maydell, 2020/11/17