aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabiano Rosas <farosas@suse.de>2025-07-16 15:26:46 -0300
committerFabiano Rosas <farosas@suse.de>2025-07-22 19:39:29 -0300
commit2251f9ac9261cda05b6b19e9ba329b15d9d89bae (patch)
treebe31006cb54fac350654a9dcc56fdabcde7808e2
parent9e601684dc24a521bb1d23215a63e5c6e79ea0bb (diff)
downloadqemu-2251f9ac9261cda05b6b19e9ba329b15d9d89bae.zip
qemu-2251f9ac9261cda05b6b19e9ba329b15d9d89bae.tar.gz
qemu-2251f9ac9261cda05b6b19e9ba329b15d9d89bae.tar.bz2
migration: HMP: Fix possible out-of-bounds access
Coverity has caught a bug in the formatting of time intervals for postcopy latency distribution display in 'info migrate'. While bounds checking the labels array, sizeof is incorrectly being used. ARRAY_SIZE is the correct form of obtaining the size of an array. Fixes: 3345fb3b6d ("migration/postcopy: Add latency distribution report for blocktime") Resolves: Coverity CID 1612248 Suggested-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Link: https://lore.kernel.org/qemu-devel/20250716182648.30202-2-farosas@suse.de Signed-off-by: Fabiano Rosas <farosas@suse.de>
-rw-r--r--migration/migration-hmp-cmds.c6
1 files changed, 2 insertions, 4 deletions
diff --git a/migration/migration-hmp-cmds.c b/migration/migration-hmp-cmds.c
index cef5608..bb95488 100644
--- a/migration/migration-hmp-cmds.c
+++ b/migration/migration-hmp-cmds.c
@@ -57,11 +57,9 @@ static const gchar *format_time_str(uint64_t us)
const char *units[] = {"us", "ms", "sec"};
int index = 0;
- while (us > 1000) {
+ while (us > 1000 && index + 1 < ARRAY_SIZE(units)) {
us /= 1000;
- if (++index >= (sizeof(units) - 1)) {
- break;
- }
+ index++;
}
return g_strdup_printf("%"PRIu64" %s", us, units[index]);