ui/keymaps: Avoid trace crash and improve error messages
PATCH 1/1 ui/keymaps: Avoid trace crash and improve error messages
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.
--- ui/keymaps.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
ui/keymaps.c +10 -4
@@ -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 ; }
Signature · 1 line
2.49.0
Quoted 11 lines · Markus Armbruster
parse_keyboard_layout()passes a possibly null @filename totrace_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 <[email protected]>
Quoted 42 lines
--- ui/keymaps.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)ui/keymaps.c +10
-5@@ -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
Quoted 6 lines · Markus Armbruster
parse_keyboard_layout()passes a possibly null @filename totrace_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().
Quoted 7 lines
While there, improve the error messages a bit.
Fixes d3b787fa7dde (keymaps: add tracing)Signed-off-by Markus Armbruster <[email protected]>--- ui/keymaps.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
Markus Armbruster
AppliedQuoted 10 lines · Markus Armbruster
parse_keyboard_layout()passes a possibly null @filename totrace_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 <[email protected]>
Queued. Thanks for the review!