[PATCH v1] vga: avoid crash if no default vga card

Guo Zhi posted 1 patch 1 year, 12 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20220503091724.970009-1-qtxuning1999@sjtu.edu.cn
Maintainers: Paolo Bonzini <pbonzini@redhat.com>
There is a newer version of this series
softmmu/vl.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
[PATCH v1] vga: avoid crash if no default vga card
Posted by Guo Zhi 1 year, 12 months ago
QEMU in some arch will crash when executing -vga help command, because
there is no default vga model.  Add check to this case and avoid crash.

Signed-off-by: Guo Zhi <qtxuning1999@sjtu.edu.cn>
---
 softmmu/vl.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/softmmu/vl.c b/softmmu/vl.c
index c2919579fd..a49e29312b 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -977,7 +977,8 @@ static void select_vgahw(const MachineClass *machine_class, const char *p)
 
             if (vga_interface_available(t) && ti->opt_name) {
                 printf("%-20s %s%s\n", ti->opt_name, ti->name ?: "",
-                       g_str_equal(ti->opt_name, def) ? " (default)" : "");
+                        (def && g_str_equal(ti->opt_name, def)) ?
+                        " (default)" : "");
             }
         }
         exit(0);
-- 
2.35.1
Re: [PATCH v1] vga: avoid crash if no default vga card
Posted by Thomas Huth 1 year, 12 months ago
On 03/05/2022 11.17, Guo Zhi wrote:
> QEMU in some arch will crash when executing -vga help command, because
> there is no default vga model.  Add check to this case and avoid crash.
> 
> Signed-off-by: Guo Zhi <qtxuning1999@sjtu.edu.cn>
> ---
>   softmmu/vl.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/softmmu/vl.c b/softmmu/vl.c
> index c2919579fd..a49e29312b 100644
> --- a/softmmu/vl.c
> +++ b/softmmu/vl.c
> @@ -977,7 +977,8 @@ static void select_vgahw(const MachineClass *machine_class, const char *p)
>   
>               if (vga_interface_available(t) && ti->opt_name) {
>                   printf("%-20s %s%s\n", ti->opt_name, ti->name ?: "",
> -                       g_str_equal(ti->opt_name, def) ? " (default)" : "");
> +                        (def && g_str_equal(ti->opt_name, def)) ?
> +                        " (default)" : "");
>               }
>           }
>           exit(0);

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/978

Reviewed-by: Thomas Huth <thuth@redhat.com>
Tested-by: Thomas Huth <thuth@redhat.com>
Re: [PATCH v1] vga: avoid crash if no default vga card
Posted by Laurent Vivier 1 year, 10 months ago
Le 03/05/2022 à 17:39, Thomas Huth a écrit :
> On 03/05/2022 11.17, Guo Zhi wrote:
>> QEMU in some arch will crash when executing -vga help command, because
>> there is no default vga model.  Add check to this case and avoid crash.
>>
>> Signed-off-by: Guo Zhi <qtxuning1999@sjtu.edu.cn>
>> ---
>>   softmmu/vl.c | 3 ++-
>>   1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/softmmu/vl.c b/softmmu/vl.c
>> index c2919579fd..a49e29312b 100644
>> --- a/softmmu/vl.c
>> +++ b/softmmu/vl.c
>> @@ -977,7 +977,8 @@ static void select_vgahw(const MachineClass *machine_class, const char *p)
>>               if (vga_interface_available(t) && ti->opt_name) {
>>                   printf("%-20s %s%s\n", ti->opt_name, ti->name ?: "",
>> -                       g_str_equal(ti->opt_name, def) ? " (default)" : "");
>> +                        (def && g_str_equal(ti->opt_name, def)) ?
>> +                        " (default)" : "");
>>               }
>>           }
>>           exit(0);
> 
> Resolves: https://gitlab.com/qemu-project/qemu/-/issues/978
> 
> Reviewed-by: Thomas Huth <thuth@redhat.com>
> Tested-by: Thomas Huth <thuth@redhat.com>
> 
>

Applied to my trivial-patches branch.

Thanks,
Laurent