From: Markus Armbruster Date: Wed, 23 Jul 2025 13:15:04 +0000 (+0200) Subject: ui/keymaps: Avoid trace crash and improve error messages X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a12ff7f807e3ae2e254ac1de45c3892831479a0f;p=thirdparty%2Fqemu.git ui/keymaps: Avoid trace crash and improve error messages parse_keyboard_layout() passes a possibly null @filename to trace_keymap_parse(). Trace backend log then formats it with %s, which crashes on some systems. Fix by moving the null check before the trace_keymap_parse(). While there, improve the error messages a bit. Fixes: d3b787fa7dde (keymaps: add tracing) Signed-off-by: Markus Armbruster Message-ID: <20250723131504.1482657-1-armbru@redhat.com> Reviewed-by: Marc-André Lureau Reviewed-by: Philippe Mathieu-Daudé --- diff --git a/ui/keymaps.c b/ui/keymaps.c index 6ceaa97085a..2359dbfe7e6 100644 --- a/ui/keymaps.c +++ b/ui/keymaps.c @@ -86,19 +86,25 @@ static int parse_keyboard_layout(kbd_layout_t *k, const name2keysym_t *table, const char *language, Error **errp) { + g_autofree char *filename = NULL; int ret; FILE *f; - char * filename; char line[1024]; char keyname[64]; int len; filename = qemu_find_file(QEMU_FILE_TYPE_KEYMAP, language); + if (!filename) { + error_setg(errp, "could not find keymap file for language '%s'", + language); + return -1; + } + trace_keymap_parse(filename); - f = filename ? fopen(filename, "r") : NULL; - g_free(filename); + + f = fopen(filename, "r"); if (!f) { - error_setg(errp, "could not read keymap file: '%s'", language); + error_setg_file_open(errp, errno, filename); return -1; }