thebeanogamer / rpms / qemu-kvm

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