* [PATCH] ui/keymaps: Avoid trace crash and improve error messages
@ 2025-07-23 13:15 Markus Armbruster
2025-07-23 13:49 ` Marc-André Lureau
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Markus Armbruster @ 2025-07-23 13:15 UTC (permalink / raw)
To: qemu-devel; +Cc: marcandre.lureau, kraxel
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 <armbru@redhat.com>
---
ui/keymaps.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/ui/keymaps.c b/ui/keymaps.c
index 6ceaa97085..2359dbfe7e 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;
}
--
2.49.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] ui/keymaps: Avoid trace crash and improve error messages
2025-07-23 13:15 [PATCH] ui/keymaps: Avoid trace crash and improve error messages Markus Armbruster
@ 2025-07-23 13:49 ` Marc-André Lureau
2025-07-23 13:53 ` Philippe Mathieu-Daudé
2025-09-01 11:12 ` Markus Armbruster
2 siblings, 0 replies; 4+ messages in thread
From: Marc-André Lureau @ 2025-07-23 13:49 UTC (permalink / raw)
To: Markus Armbruster; +Cc: qemu-devel, kraxel
[-- Attachment #1: Type: text/plain, Size: 1768 bytes --]
On Wed, Jul 23, 2025 at 5:15 PM Markus Armbruster <armbru@redhat.com> wrote:
> 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 <armbru@redhat.com>
>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
> ui/keymaps.c | 14 ++++++++++----
> 1 file changed, 10 insertions(+), 4 deletions(-)
>
> diff --git a/ui/keymaps.c b/ui/keymaps.c
> index 6ceaa97085..2359dbfe7e 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;
> }
>
> --
> 2.49.0
>
>
[-- Attachment #2: Type: text/html, Size: 2643 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] ui/keymaps: Avoid trace crash and improve error messages
2025-07-23 13:15 [PATCH] ui/keymaps: Avoid trace crash and improve error messages Markus Armbruster
2025-07-23 13:49 ` Marc-André Lureau
@ 2025-07-23 13:53 ` Philippe Mathieu-Daudé
2025-09-01 11:12 ` Markus Armbruster
2 siblings, 0 replies; 4+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-07-23 13:53 UTC (permalink / raw)
To: Markus Armbruster, qemu-devel; +Cc: marcandre.lureau, kraxel
On 23/7/25 15:15, Markus Armbruster wrote:
> 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 <armbru@redhat.com>
> ---
> ui/keymaps.c | 14 ++++++++++----
> 1 file changed, 10 insertions(+), 4 deletions(-)
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] ui/keymaps: Avoid trace crash and improve error messages
2025-07-23 13:15 [PATCH] ui/keymaps: Avoid trace crash and improve error messages Markus Armbruster
2025-07-23 13:49 ` Marc-André Lureau
2025-07-23 13:53 ` Philippe Mathieu-Daudé
@ 2025-09-01 11:12 ` Markus Armbruster
2 siblings, 0 replies; 4+ messages in thread
From: Markus Armbruster @ 2025-09-01 11:12 UTC (permalink / raw)
To: qemu-devel; +Cc: marcandre.lureau, kraxel
Markus Armbruster <armbru@redhat.com> writes:
> 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 <armbru@redhat.com>
Queued. Thanks for the review!
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-09-01 12:07 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-23 13:15 [PATCH] ui/keymaps: Avoid trace crash and improve error messages Markus Armbruster
2025-07-23 13:49 ` Marc-André Lureau
2025-07-23 13:53 ` Philippe Mathieu-Daudé
2025-09-01 11:12 ` Markus Armbruster
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).