Commit 1d06e84aa7 for qemu.org
commit 1d06e84aa75e880ba1e859c6ee157306702ab3c1
Author: Carlo Marcelo Arenas Belón <carenas@gmail.com>
Date: Sun Aug 2 09:28:28 2026 -0700
hw/arm/aspeed: avoid sign mismatch on sscanf for uart property
using "%u" with sscanf() was likely meant to indicate that a
negative value was unexpected, but with a signed variable it
could result in undefined behaviour.
use "%d" and check for a negative input explicitly.
Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>
Reviewed-by: Cédric Le Goater <clg@redhat.com>
Link: https://lore.kernel.org/qemu-devel/20260802162828.16880-1-carenas@gmail.com
Signed-off-by: Cédric Le Goater <clg@redhat.com>
diff --git a/hw/arm/aspeed.c b/hw/arm/aspeed.c
index a48c442058..a9238e6217 100644
--- a/hw/arm/aspeed.c
+++ b/hw/arm/aspeed.c
@@ -327,7 +327,7 @@ static void aspeed_set_bmc_console(Object *obj, const char *value, Error **errp)
int uart_first = aspeed_uart_first(sc->uarts_base);
int uart_last = aspeed_uart_last(sc->uarts_base, sc->uarts_num);
- if (sscanf(value, "uart%u", &val) != 1) {
+ if (sscanf(value, "uart%d", &val) != 1 || val < 0) {
error_setg(errp, "Bad value for \"uart\" property");
return;
}