@samitouri / QOSamiQemu / commits / c862a1e7e2

ui/vt100: Take byte as uint8_t in bh_utf8_decode()

The bh_utf8_decode() UTF8 decoder takes its next byte as a "uint32_t byte" parameter, but it assumes it to be in bounds as it immediately indexes into its array with it. Use "uint8_t" as the argument type instead. This moves us away from the upstream implementation slightly, but it is the same type as we use in the one callsite, and it makes it clear that we can't be indexing off the end of the array with this guest-derived data. This probably helps make Coverity a bit happier (CID 1659590). Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-ID: <20260512104210.3330835-3-peter.maydell@linaro.org>

Peter Maydell committed May 12, 2026 at 11:42 UTC c862a1e7e258d56d3bb67d3dbde8311b1bf7e494
1 file changed +1 -1
ui/vt100.c
+1 -1
@@ -438,7 +438,7 @@ static void vt100_clear_xy(QemuVT100 *vt, int x, int y)
438 #define BH_UTF8_ACCEPT 0
439 #define BH_UTF8_REJECT 12
440
441 -static uint32_t bh_utf8_decode(uint32_t *state, uint32_t *codep, uint32_t byte)
441 +static uint32_t bh_utf8_decode(uint32_t *state, uint32_t *codep, uint8_t byte)
442 {
443 static const uint8_t utf8d[] = {
444 /* character class lookup */