console: Fix segfault on screendump without VGA adapter
PATCH 1/1 console: Fix segfault on screendump without VGA adapter
When trying to create a screen dump without having any VGA adapter inside the guest, QEMU segfaults.
This is because it's trying to switch back to the "previous" screen it was on before dumping the VGA screen. Unfortunately, in my case there simply is no previous screen so it accesses a NULL pointer.
Fix it by checking if previous_active_console is actually available.
This is 1.0 material.
--- console.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-)
console.c +3 -1
@@ -186,7 +186,9 @@ void vga_hw_screen_dump(const char *filename) consoles[0 ]->hw_screen_dump (consoles[0 ]->hw, filename); } -console_select (previous_active_console->index); +if (previous_active_console) { +console_select (previous_active_console->index); + } }void vga_hw_text_update (console_ch_t *chardata)
Signature · 1 line
1.6.0.2
PATCH 1/1 creen dump not supported when no console
I have tested the issue use "-vga none -nographic" option. QEMU segment faults.
But i think there is no any text and graphic console created in this case. The console[0] is NULL.
The vga_hw_screen_dump() should return before console_select(). What do you think?
--- console.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
console.c +3 -0
@@ -184,6 +184,9 @@ void vga_hw_screen_dump(const char *filename)console_select (0 );if (consoles[0 ] && consoles[0 ]->hw_screen_dump) { consoles[0 ]->hw_screen_dump (consoles[0 ]->hw, filename); + }else { +fprintf (stderr,"no any console,could not screen dump \n" ); +return ; }console_select (previous_active_console->index);
Signature · 1 line
1.7.1
Re: [Qemu-devel] [PATCH] creen dump not supported when no console
console.c void vga_hw_screen_dump(const char *filename) · line 189
Quoted 3 lines · Cao,Bing Bu
console.c +3
-0+ }else { +fprintf (stderr,"no any console,could not screen dump \n" ); +return ;
This should be error_printf.
Paolo
PATCH v2 1/1 Can't screendump without a console
When usinge "-vga none -nographic" option.
There is no any text and graphic console created in this case. screen dump not supported without console.
--- console.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-)
console.c +3 -1
@@ -184,8 +184,10 @@ void vga_hw_screen_dump(const char *filename)console_select (0 );if (consoles[0 ] && consoles[0 ]->hw_screen_dump) { consoles[0 ]->hw_screen_dump (consoles[0 ]->hw, filename); + }else { +error_printf ("no any console,could not screen dump \n" ); +return ; } -console_select (previous_active_console->index); }
Signature · 1 line
1.7.1
Re: [Qemu-devel] [PATCH] creen dump not supported when no console
In reply to Cao,Bing BuQuoted 19 lines · Cao,Bing Bu
I have tested the issue use "-vga none -nographic" option. QEMU segment faults.
But i think there is no any text and graphic console created in this case. The console[0] is NULL.
The
vga_hw_screen_dump()should return beforeconsole_select(). What do you think?--- console.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)console.c +0
-0
console.c void vga_hw_screen_dump(const char *filename) · line 192
Quoted 9 lines
console.c +3
-0@@ -184,6 +184,9 @@ void vga_hw_screen_dump(const char *filename)console_select (0 );if (consoles[0 ] && consoles[0 ]->hw_screen_dump) { consoles[0 ]->hw_screen_dump (consoles[0 ]->hw, filename); + }else { +fprintf (stderr,"no any console,could not screen dump \n" ); +return ; }console_select (previous_active_console->index);
Tab damage.
Subject misspells "screendump".
Error message could use some polish. Suggest "Can't screendump without a console".
Please don't use printf & friends for output to the monitor user, it doesn't go to the monitor unless the monitor happens to be on stdio. Use error_printf() & friends.
Except when the command is in QMP, and you need nice error reports in QMP. Then use qerror_report(). Yes, that's a pain to use.
Except when the command is already implemented in QAPI. Then you use error_set() instead. Yes, that one's a PITA, too.