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: d3b787fa7d (keymaps: add tracing)
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-ID: <20250723131504.1482657-1-armbru@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
This commit is contained in:
Markus Armbruster 2025-07-23 15:15:04 +02:00
parent 91589bcd9f
commit a12ff7f807

View file

@ -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;
}