From: Li Qiang <liq3ea@gmail.com>
To: Markus Armbruster <armbru@redhat.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>,
Qemu Developers <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [PATCH] keymaps: detect recursive keyboard layout file
Date: Fri, 16 Nov 2018 11:14:30 +0800 [thread overview]
Message-ID: <CAKXe6SLv4ob4NqnbwwEYfYbf3D=v9mNvAzxe329tMR52PZfiQg@mail.gmail.com> (raw)
In-Reply-To: <87bm6qh3kc.fsf@dusky.pond.sub.org>
Markus Armbruster <armbru@redhat.com> 于2018年11月15日周四 下午9:29写道:
> Li Qiang <liq3ea@gmail.com> writes:
>
> > When the parse_keyboard_layout() find a "include " line
> > in the keyboard layout file, it will call parse_keyboard_layout()
> > to perform a recursive parse. If the keyboard layout is malformed
> > by adding a line include itself, this can cause an infinite parse.
> > Thus cause qemu a segv. This patch avoid this.
> >
> > Signed-off-by: Li Qiang <liq3ea@gmail.com>
> > ---
> > ui/keymaps.c | 17 ++++++++++++++++-
> > 1 file changed, 16 insertions(+), 1 deletion(-)
> >
> > diff --git a/ui/keymaps.c b/ui/keymaps.c
> > index 085889b555..564893a9f3 100644
> > --- a/ui/keymaps.c
> > +++ b/ui/keymaps.c
> > @@ -38,6 +38,8 @@ struct kbd_layout_t {
> > GHashTable *hash;
> > };
> >
> > +GList *keyboard_files;
> > +
> > static int get_keysym(const name2keysym_t *table,
> > const char *name)
> > {
> > @@ -80,6 +82,11 @@ static void add_keysym(char *line, int keysym, int
> keycode, kbd_layout_t *k)
> > trace_keymap_add(keysym, keycode, line);
> > }
> >
> > +static gint compare_string(gconstpointer a, gconstpointer b)
> > +{
> > + return g_strcmp0(a, b);
> > +}
> > +
> > static int parse_keyboard_layout(kbd_layout_t *k,
> > const name2keysym_t *table,
> > const char *language, Error **errp)
> > @@ -94,12 +101,18 @@ static int parse_keyboard_layout(kbd_layout_t *k,
> > filename = qemu_find_file(QEMU_FILE_TYPE_KEYMAP, language);
> > trace_keymap_parse(filename);
> > f = filename ? fopen(filename, "r") : NULL;
> > - g_free(filename);
> > if (!f) {
> > + g_free(filename);
> > error_setg(errp, "could not read keymap file: '%s'", language);
> > return -1;
> > }
> >
> > + if (g_list_find_custom(keyboard_files, filename, compare_string)) {
> > + error_setg(errp, "find recursive keyboard layout: %s'",
> filename);
>
> Suggest something like "Inclusion loop for %s".
>
> > + g_free(filename);
> > + return -1;
> > + }
> > + keyboard_files = g_list_append(keyboard_files, filename);
> > for(;;) {
> > if (fgets(line, 1024, f) == NULL) {
> > break;
> > @@ -168,6 +181,8 @@ static int parse_keyboard_layout(kbd_layout_t *k,
> > ret = 0;
> > out:
> > fclose(f);
> > + keyboard_files = g_list_remove(keyboard_files, filename);
> > + g_free(filename);
> > return ret;
> > }
>
> There's no real need to make @keyboard_files global. I'd make it local
> to init_keyboard_layout(), and pass it as argument to
> parse_keyboard_layout().
Thanks Markus,
Finally, Gerd decide remove the support of "include" in keymaps.
Thanks,
Li Qiang
> Matter of taste. Gerd is the maintainer, not
> me.
>
prev parent reply other threads:[~2018-11-16 3:15 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-15 9:04 [Qemu-devel] [PATCH] keymaps: detect recursive keyboard layout file Li Qiang
2018-11-15 10:15 ` Gerd Hoffmann
2018-11-15 10:22 ` Li Qiang
2018-11-15 13:29 ` Markus Armbruster
2018-11-16 3:14 ` Li Qiang [this message]
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='CAKXe6SLv4ob4NqnbwwEYfYbf3D=v9mNvAzxe329tMR52PZfiQg@mail.gmail.com' \
--to=liq3ea@gmail.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).