Re: [PATCH] qemu: Fix crash in virQEMUCapsProbeQMPTPM

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Jul 12, 2021 at 04:25:59PM +0200, Peter Krempa wrote:
> If the queried QMP command doesn't exist qemuMonitorGetTPMModels returns
> 0 but sets the string list to NULL which isn't accepted by
> g_strv_contains.
> 
> Fixes: a5bc5f0ecf8
> Reported-by: Olaf Hering <olaf@xxxxxxxxx>
> Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
> ---
>  src/qemu/qemu_capabilities.c | 13 +++++++++----
>  1 file changed, 9 insertions(+), 4 deletions(-)
> 
> diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
> index d1cd8f11ac..5b359258a1 100644
> --- a/src/qemu/qemu_capabilities.c
> +++ b/src/qemu/qemu_capabilities.c
> @@ -3168,6 +3168,9 @@ virQEMUCapsProbeQMPTPM(virQEMUCaps *qemuCaps,
>      if (qemuMonitorGetTPMModels(mon, &models) < 0)
>          return -1;
> 
> +    if (!models)
> +        return 0;
> +
>      for (i = 0; i < G_N_ELEMENTS(virQEMUCapsTPMModelsToCaps); i++) {
>          const char *needle = virDomainTPMModelTypeToString(virQEMUCapsTPMModelsToCaps[i].type);
>          if (g_strv_contains((const char **)models, needle))
> @@ -3177,10 +3180,12 @@ virQEMUCapsProbeQMPTPM(virQEMUCaps *qemuCaps,
>      if (qemuMonitorGetTPMTypes(mon, &types) < 0)
>          return -1;
> 
> -    for (i = 0; i < G_N_ELEMENTS(virQEMUCapsTPMTypesToCaps); i++) {
> -        const char *needle = virDomainTPMBackendTypeToString(virQEMUCapsTPMTypesToCaps[i].type);
> -        if (g_strv_contains((const char **)types, needle))
> -            virQEMUCapsSet(qemuCaps, virQEMUCapsTPMTypesToCaps[i].caps);
> +    if (types) {
> +        for (i = 0; i < G_N_ELEMENTS(virQEMUCapsTPMTypesToCaps); i++) {
> +            const char *needle = virDomainTPMBackendTypeToString(virQEMUCapsTPMTypesToCaps[i].type);
> +            if (g_strv_contains((const char **)types, needle))
> +                virQEMUCapsSet(qemuCaps, virQEMUCapsTPMTypesToCaps[i].caps);
> +        }

Why not:

    if (!types)
        return 0;

to remain consistent with the essentially same fix in the first hunk? :)


Reviewed-by: Erik Skultety <eskultet@redhat>

>      }
> 
>      return 0;
> -- 
> 2.31.1
> 




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux