From nobody Thu Nov 6 06:15:27 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1539605529488887.1276741032572; Mon, 15 Oct 2018 05:12:09 -0700 (PDT) Received: from localhost ([::1]:51908 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gC1jE-000196-35 for importer@patchew.org; Mon, 15 Oct 2018 08:12:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39660) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gC1RD-0004GV-53 for qemu-devel@nongnu.org; Mon, 15 Oct 2018 07:53:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gC1RA-0002Az-Vx for qemu-devel@nongnu.org; Mon, 15 Oct 2018 07:53:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34586) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gC1R9-00024f-0i for qemu-devel@nongnu.org; Mon, 15 Oct 2018 07:53:27 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 052BF550CC for ; Mon, 15 Oct 2018 11:53:21 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-50.ams2.redhat.com [10.36.116.50]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 805F07B5E1; Mon, 15 Oct 2018 11:53:17 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 0879411562E4; Mon, 15 Oct 2018 13:53:10 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 15 Oct 2018 13:52:59 +0200 Message-Id: <20181015115309.17089-26-armbru@redhat.com> In-Reply-To: <20181015115309.17089-1-armbru@redhat.com> References: <20181015115309.17089-1-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 15 Oct 2018 11:53:21 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 25/35] ui/keymaps: Fix handling of erroneous include files X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" While errors in the keyboard layout named with -k are fatal, errors in included files are reported, but otherwise ignored: $ cat worst include bad include worse $ ls -l bad worse ls: cannot access 'bad': No such file or directory ls: cannot access 'worse': No such file or directory $ qemu-system-x86_64 -nodefaults -S -monitor stdio -display vnc=3D:0 -k= bad QEMU 3.0.50 monitor - type 'help' for more information (qemu) Could not read keymap file: 'bad' $ qemu-system-x86_64 -nodefaults -S -monitor stdio -display vnc=3D:0 -k= worst QEMU 3.0.50 monitor - type 'help' for more information (qemu) Could not read keymap file: 'bad' Could not read keymap file: 'worse' Fix that. Note that parse_keyboard_layout() allocates the keymap, except when it's parsing an include file. To keep error handling simple, move the memory management to its caller init_keyboard_layout(). Cc: Gerd Hoffmann Signed-off-by: Markus Armbruster --- ui/keymaps.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/ui/keymaps.c b/ui/keymaps.c index 43fe604724..b05fb028dc 100644 --- a/ui/keymaps.c +++ b/ui/keymaps.c @@ -79,10 +79,11 @@ static void add_keysym(char *line, int keysym, int keyc= ode, kbd_layout_t *k) trace_keymap_add(keysym, keycode, line); } =20 -static kbd_layout_t *parse_keyboard_layout(const name2keysym_t *table, - const char *language, - kbd_layout_t *k) +static int parse_keyboard_layout(kbd_layout_t *k, + const name2keysym_t *table, + const char *language) { + int ret; FILE *f; char * filename; char line[1024]; @@ -95,12 +96,7 @@ static kbd_layout_t *parse_keyboard_layout(const name2ke= ysym_t *table, g_free(filename); if (!f) { fprintf(stderr, "Could not read keymap file: '%s'\n", language); - return NULL; - } - - if (!k) { - k =3D g_new0(kbd_layout_t, 1); - k->hash =3D g_hash_table_new(NULL, NULL); + return -1; } =20 for(;;) { @@ -118,7 +114,10 @@ static kbd_layout_t *parse_keyboard_layout(const name2= keysym_t *table, continue; } if (!strncmp(line, "include ", 8)) { - parse_keyboard_layout(table, line + 8, k); + if (parse_keyboard_layout(k, table, line + 8) < 0) { + ret =3D -1; + goto out; + } } else { int offset =3D 0; while (line[offset] !=3D 0 && @@ -164,15 +163,27 @@ static kbd_layout_t *parse_keyboard_layout(const name= 2keysym_t *table, } } } + + ret =3D 0; +out: fclose(f); - return k; + return ret; } =20 =20 kbd_layout_t *init_keyboard_layout(const name2keysym_t *table, const char *language) { - return parse_keyboard_layout(table, language, NULL); + kbd_layout_t *k; + + k =3D g_new0(kbd_layout_t, 1); + k->hash =3D g_hash_table_new(NULL, NULL); + if (parse_keyboard_layout(k, table, language) < 0) { + g_hash_table_unref(k->hash); + g_free(k); + return NULL; + } + return k; } =20 =20 --=20 2.17.1