cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
dc1fe0
From 965275cd87f8008f129509c6d6fd0096e8ac2d96 Mon Sep 17 00:00:00 2001
dc1fe0
From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= <marcandre.lureau@redhat.com>
dc1fe0
Date: Mon, 14 Feb 2022 15:59:17 +0400
dc1fe0
Subject: [PATCH 3/6] ui/clipboard: fix use-after-free regression
dc1fe0
MIME-Version: 1.0
dc1fe0
Content-Type: text/plain; charset=UTF-8
dc1fe0
Content-Transfer-Encoding: 8bit
dc1fe0
dc1fe0
RH-Author: Gerd Hoffmann <kraxel@redhat.com>
dc1fe0
RH-MergeRequest: 75: fix vnc cut+paste crash
dc1fe0
RH-Commit: [3/4] d8f68e0eb60d9aaa9a703d969f215816bf35f6f0 (kraxel/centos-qemu-kvm)
dc1fe0
RH-Bugzilla: 2042820
dc1fe0
RH-Acked-by: Marc-André Lureau <marcandre.lureau@redhat.com>
dc1fe0
RH-Acked-by: Daniel P. Berrangé <berrange@redhat.com>
dc1fe0
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
dc1fe0
dc1fe0
The same info may be used to update the clipboard, and may be freed
dc1fe0
before being ref'ed again.
dc1fe0
dc1fe0
Fixes: 70a54b01693ed ("ui: avoid compiler warnings from unused clipboard info variable")
dc1fe0
dc1fe0
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
dc1fe0
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
dc1fe0
Message-Id: <20220214115917.1679568-1-marcandre.lureau@redhat.com>
dc1fe0
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
dc1fe0
---
dc1fe0
 ui/clipboard.c | 6 ++++--
dc1fe0
 1 file changed, 4 insertions(+), 2 deletions(-)
dc1fe0
dc1fe0
diff --git a/ui/clipboard.c b/ui/clipboard.c
dc1fe0
index 7672058e84..d7dae13760 100644
dc1fe0
--- a/ui/clipboard.c
dc1fe0
+++ b/ui/clipboard.c
dc1fe0
@@ -48,8 +48,10 @@ void qemu_clipboard_update(QemuClipboardInfo *info)
dc1fe0
 
dc1fe0
     notifier_list_notify(&clipboard_notifiers, info);
dc1fe0
 
dc1fe0
-    qemu_clipboard_info_unref(cbinfo[info->selection]);
dc1fe0
-    cbinfo[info->selection] = qemu_clipboard_info_ref(info);
dc1fe0
+    if (cbinfo[info->selection] != info) {
dc1fe0
+        qemu_clipboard_info_unref(cbinfo[info->selection]);
dc1fe0
+        cbinfo[info->selection] = qemu_clipboard_info_ref(info);
dc1fe0
+    }
dc1fe0
 }
dc1fe0
 
dc1fe0
 QemuClipboardInfo *qemu_clipboard_info(QemuClipboardSelection selection)
dc1fe0
-- 
dc1fe0
2.27.0
dc1fe0