[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v4 25/38] ui/keymaps: Fix handling of erroneous incl
From: |
Markus Armbruster |
Subject: |
[Qemu-devel] [PATCH v4 25/38] ui/keymaps: Fix handling of erroneous include files |
Date: |
Wed, 17 Oct 2018 10:26:49 +0200 |
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=: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=: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 <address@hidden>
Signed-off-by: Markus Armbruster <address@hidden>
---
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 keycode,
kbd_layout_t *k)
trace_keymap_add(keysym, keycode, line);
}
-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
name2keysym_t *table,
g_free(filename);
if (!f) {
fprintf(stderr, "Could not read keymap file: '%s'\n", language);
- return NULL;
- }
-
- if (!k) {
- k = g_new0(kbd_layout_t, 1);
- k->hash = g_hash_table_new(NULL, NULL);
+ return -1;
}
for(;;) {
@@ -118,7 +114,10 @@ static kbd_layout_t *parse_keyboard_layout(const
name2keysym_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 = -1;
+ goto out;
+ }
} else {
int offset = 0;
while (line[offset] != 0 &&
@@ -164,15 +163,27 @@ static kbd_layout_t *parse_keyboard_layout(const
name2keysym_t *table,
}
}
}
+
+ ret = 0;
+out:
fclose(f);
- return k;
+ return ret;
}
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 = g_new0(kbd_layout_t, 1);
+ k->hash = 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;
}
--
2.17.1
- [Qemu-devel] [PATCH v4 34/38] vl: Fix exit status for -drive format=help, (continued)
- [Qemu-devel] [PATCH v4 34/38] vl: Fix exit status for -drive format=help, Markus Armbruster, 2018/10/17
- [Qemu-devel] [PATCH v4 35/38] vl: Simplify call of parse_name(), Markus Armbruster, 2018/10/17
- [Qemu-devel] [PATCH v4 07/38] char: Use error_printf() to print help and such, Markus Armbruster, 2018/10/17
- [Qemu-devel] [PATCH v4 31/38] fsdev: Clean up error reporting in qemu_fsdev_add(), Markus Armbruster, 2018/10/17
- [Qemu-devel] [PATCH v4 36/38] block: Clean up bdrv_img_create()'s error reporting, Markus Armbruster, 2018/10/17
- [Qemu-devel] [PATCH v4 09/38] pc: Fix machine property nvdimm-persistence error handling, Markus Armbruster, 2018/10/17
- [Qemu-devel] [PATCH v4 10/38] ioapic: Fix error handling in realize(), Markus Armbruster, 2018/10/17
- [Qemu-devel] [PATCH v4 17/38] seccomp: Clean up error reporting in parse_sandbox(), Markus Armbruster, 2018/10/17
- [Qemu-devel] [PATCH v4 05/38] vfio: Use warn_report() & friends to report warnings, Markus Armbruster, 2018/10/17
- [Qemu-devel] [PATCH v4 25/38] ui/keymaps: Fix handling of erroneous include files,
Markus Armbruster <=
- [Qemu-devel] [PATCH v4 26/38] ui: Convert vnc_display_init(), init_keyboard_layout() to Error, Markus Armbruster, 2018/10/17
- [Qemu-devel] [PATCH v4 04/38] cpus hw target: Use warn_report() & friends to report warnings, Markus Armbruster, 2018/10/17
- [Qemu-devel] [PATCH v4 37/38] raw: Convert a warning to warn_report(), Markus Armbruster, 2018/10/17
- [Qemu-devel] [PATCH v4 38/38] vpc: Fail open on bad header checksum, Markus Armbruster, 2018/10/17