[RFC] ui/vnc: Fix qemu abort when query vnc info

AlanoSong@163.com posted 1 patch 2 months, 1 week ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20251125122059.24420-1-AlanoSong@163.com
Maintainers: "Marc-André Lureau" <marcandre.lureau@redhat.com>
There is a newer version of this series
ui/vnc.c | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)
[RFC] ui/vnc: Fix qemu abort when query vnc info
Posted by AlanoSong@163.com 2 months, 1 week ago
From: Alano Song <AlanoSong@163.com>

When there is no display device on qemu machine,
and user only access qemu by remote vnc.
At the same time user input `info vnc` by QMP,
the qemu will abort.

To avoid the abort above, I add display device check,
when query vnc info in qmp_query_vnc_servers().

Signed-off-by: Alano Song <AlanoSong@163.com>
---
 ui/vnc.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/ui/vnc.c b/ui/vnc.c
index 0d499b208b..2fa79a5494 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -556,9 +556,20 @@ VncInfo2List *qmp_query_vnc_servers(Error **errp)
         qmp_query_auth(vd->auth, vd->subauth, &info->auth,
                        &info->vencrypt, &info->has_vencrypt);
         if (vd->dcl.con) {
-            dev = DEVICE(object_property_get_link(OBJECT(vd->dcl.con),
-                                                  "device", &error_abort));
-            info->display = g_strdup(dev->id);
+            Error *err = NULL;
+            Object *obj = object_property_get_link(OBJECT(vd->dcl.con),
+                                                   "device", &err);
+            if (obj) {
+                dev = DEVICE(obj);
+                if (dev && dev->id) {
+                    info->display = g_strdup(dev->id);
+                } else {
+                    info->display = g_strdup("unknown");
+                }
+            } else {
+                info->display = g_strdup("none");
+                error_free(err);
+            }
         }
         if (vd->listener != NULL) {
             nsioc = qio_net_listener_nsioc(vd->listener);
-- 
2.43.0
Re: [RFC] ui/vnc: Fix qemu abort when query vnc info
Posted by Marc-André Lureau 2 months, 1 week ago
Hi

On Tue, Nov 25, 2025 at 4:32 PM <AlanoSong@163.com> wrote:

> From: Alano Song <AlanoSong@163.com>
>
> When there is no display device on qemu machine,
> and user only access qemu by remote vnc.
> At the same time user input `info vnc` by QMP,
> the qemu will abort.
>
> To avoid the abort above, I add display device check,
> when query vnc info in qmp_query_vnc_servers().
>
> Signed-off-by: Alano Song <AlanoSong@163.com>
>

Good catch, lgtm


> ---
>  ui/vnc.c | 17 ++++++++++++++---
>  1 file changed, 14 insertions(+), 3 deletions(-)
>
> diff --git a/ui/vnc.c b/ui/vnc.c
> index 0d499b208b..2fa79a5494 100644
> --- a/ui/vnc.c
> +++ b/ui/vnc.c
> @@ -556,9 +556,20 @@ VncInfo2List *qmp_query_vnc_servers(Error **errp)
>          qmp_query_auth(vd->auth, vd->subauth, &info->auth,
>                         &info->vencrypt, &info->has_vencrypt);
>          if (vd->dcl.con) {
> -            dev = DEVICE(object_property_get_link(OBJECT(vd->dcl.con),
> -                                                  "device",
> &error_abort));
> -            info->display = g_strdup(dev->id);
> +            Error *err = NULL;
> +            Object *obj = object_property_get_link(OBJECT(vd->dcl.con),
> +                                                   "device", &err);
> +            if (obj) {
> +                dev = DEVICE(obj);
> +                if (dev && dev->id) {
> +                    info->display = g_strdup(dev->id);
> +                } else {
> +                    info->display = g_strdup("unknown");
> +                }
>

info->display = g_strdup(dev->id);

as it is fine, it will set it to NULL if doesn't have an id.

+            } else {
> +                info->display = g_strdup("none");
>

This should be dropped. This way the "display" field isn't even produced,
and client can distinguish the case of associated/non-associated display.



+                error_free(err);
> +            }
>          }
>          if (vd->listener != NULL) {
>              nsioc = qio_net_listener_nsioc(vd->listener);
> --
> 2.43.0
>
>