From: "Marc-André Lureau" <marcandre.lureau@redhat.com>
To: Markus Armbruster <armbru@redhat.com>
Cc: qemu-devel@nongnu.org, kraxel@redhat.com
Subject: Re: [PATCH] ui/keymaps: Avoid trace crash and improve error messages
Date: Wed, 23 Jul 2025 17:49:37 +0400 [thread overview]
Message-ID: <CAMxuvay2YWOOWB0ak7y+eRpKwAUa68r0cym_MSsTqEcEHw1Fng@mail.gmail.com> (raw)
In-Reply-To: <20250723131504.1482657-1-armbru@redhat.com>
[-- 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 --]
next prev parent reply other threads:[~2025-07-23 13:51 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2025-07-23 13:53 ` Philippe Mathieu-Daudé
2025-09-01 11:12 ` Markus Armbruster
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAMxuvay2YWOOWB0ak7y+eRpKwAUa68r0cym_MSsTqEcEHw1Fng@mail.gmail.com \
--to=marcandre.lureau@redhat.com \
--cc=armbru@redhat.com \
--cc=kraxel@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).