From nobody Tue May 7 16:28:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520525999110254.65608533641534; Thu, 8 Mar 2018 08:19:59 -0800 (PST) Received: from localhost ([::1]:40000 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1etyGj-0006JI-DO for importer@patchew.org; Thu, 08 Mar 2018 11:19:49 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38146) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1etyF8-0005bI-VH for qemu-devel@nongnu.org; Thu, 08 Mar 2018 11:18:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1etyF2-00014c-Uy for qemu-devel@nongnu.org; Thu, 08 Mar 2018 11:18:10 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:34726 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1etyF2-00014H-Oj for qemu-devel@nongnu.org; Thu, 08 Mar 2018 11:18:04 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4CF834000787; Thu, 8 Mar 2018 16:18:04 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-39.ams2.redhat.com [10.36.116.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id 08ABA2023227; Thu, 8 Mar 2018 16:18:04 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 56A1D17513; Thu, 8 Mar 2018 17:18:03 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Thu, 8 Mar 2018 17:18:03 +0100 Message-Id: <20180308161803.6152-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Thu, 08 Mar 2018 16:18:04 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Thu, 08 Mar 2018 16:18:04 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kraxel@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH] vnc: deal with surface NULL pointers X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Christian Borntraeger , Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Secondary displays in multihead setups are allowed to have a NULL DisplaySurface. Typically user interfaces handle this by hiding the window which shows the display in question. This isn't an option for vnc though because it simply hasn't a concept of windows or outputs. So handle the situation by showing a placeholder DisplaySurface instead. Also check in console_select whenever a surface is preset in the first place before requesting an update. This fixes a segfault which can be triggered by switching to an unused display (via vtrl-alt-) in a multihead setup, for example using -device virtio-vga,max_outputs=3D2. Cc: Christian Borntraeger Signed-off-by: Gerd Hoffmann Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Christian Borntraeger --- include/ui/console.h | 2 ++ ui/console.c | 10 ++++++---- ui/vnc.c | 10 ++++++++++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/include/ui/console.h b/include/ui/console.h index aae9e44cb3..5fca9afcbc 100644 --- a/include/ui/console.h +++ b/include/ui/console.h @@ -260,6 +260,8 @@ DisplaySurface *qemu_create_displaysurface_guestmem(int= width, int height, pixman_format_code_t f= ormat, int linesize, uint64_t addr); +DisplaySurface *qemu_create_message_surface(int w, int h, + const char *msg); PixelFormat qemu_default_pixelformat(int bpp); =20 DisplaySurface *qemu_create_displaysurface(int width, int height); diff --git a/ui/console.c b/ui/console.c index 6ab4ff3baf..348610dd43 100644 --- a/ui/console.c +++ b/ui/console.c @@ -1039,8 +1039,10 @@ void console_select(unsigned int index) dcl->ops->dpy_gfx_switch(dcl, s->surface); } } - dpy_gfx_update(s, 0, 0, surface_width(s->surface), - surface_height(s->surface)); + if (s->surface) { + dpy_gfx_update(s, 0, 0, surface_width(s->surface), + surface_height(s->surface)); + } } if (ds->have_text) { dpy_text_resize(s, s->width, s->height); @@ -1370,8 +1372,8 @@ DisplaySurface *qemu_create_displaysurface_guestmem(i= nt width, int height, return surface; } =20 -static DisplaySurface *qemu_create_message_surface(int w, int h, - const char *msg) +DisplaySurface *qemu_create_message_surface(int w, int h, + const char *msg) { DisplaySurface *surface =3D qemu_create_displaysurface(w, h); pixman_color_t bg =3D color_table_rgb[0][QEMU_COLOR_BLACK]; diff --git a/ui/vnc.c b/ui/vnc.c index 13c28cabb0..e164eb798c 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -746,9 +746,19 @@ static void vnc_update_server_surface(VncDisplay *vd) static void vnc_dpy_switch(DisplayChangeListener *dcl, DisplaySurface *surface) { + static const char placeholder_msg[] =3D + "Display output is not active."; + static DisplaySurface *placeholder; VncDisplay *vd =3D container_of(dcl, VncDisplay, dcl); VncState *vs; =20 + if (surface =3D=3D NULL) { + if (placeholder =3D=3D NULL) { + placeholder =3D qemu_create_message_surface(640, 480, placehol= der_msg); + } + surface =3D placeholder; + } + vnc_abort_display_jobs(vd); vd->ds =3D surface; =20 --=20 2.9.3