peterdelevoryas / rpms / qemu

Forked from rpms/qemu 2 years ago
Clone

Blame 0032-chardev-fix-pty_chr_timer.patch

298366
From 4b5b4721464495fe76fe6e2e033cbb61dce78eef Mon Sep 17 00:00:00 2001
298366
From: Gerd Hoffmann <kraxel@redhat.com>
298366
Date: Thu, 22 Aug 2013 11:43:58 +0200
298366
Subject: [PATCH] chardev: fix pty_chr_timer
298366
298366
pty_chr_timer first calls pty_chr_update_read_handler(), then clears
298366
timer_tag (because it is a one-shot timer).   This is the wrong order
298366
though.  pty_chr_update_read_handler might re-arm time timer, and the
298366
new timer_tag gets overwitten in that case.
298366
298366
This leads to crashes when unplugging a pty chardev:  pty_chr_close
298366
thinks no timer is running -> timer isn't canceled -> pty_chr_timer gets
298366
called with stale CharDevState -> BOOM.
298366
298366
This patch fixes the ordering.
298366
Kill the pointless goto while being at it.
298366
298366
https://bugzilla.redhat.com/show_bug.cgi?id=994414
298366
298366
Cc: qemu-stable@nongnu.org
298366
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
298366
(cherry picked from commit b0d768c35e08d2057b63e8e77e7a513c447199fa)
298366
298366
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
298366
---
298366
 qemu-char.c | 12 ++++--------
298366
 1 file changed, 4 insertions(+), 8 deletions(-)
298366
298366
diff --git a/qemu-char.c b/qemu-char.c
298366
index 1be1cf6..1621fbd 100644
298366
--- a/qemu-char.c
298366
+++ b/qemu-char.c
298366
@@ -1026,15 +1026,11 @@ static gboolean pty_chr_timer(gpointer opaque)
298366
     struct CharDriverState *chr = opaque;
298366
     PtyCharDriver *s = chr->opaque;
298366
 
298366
-    if (s->connected) {
298366
-        goto out;
298366
-    }
298366
-
298366
-    /* Next poll ... */
298366
-    pty_chr_update_read_handler(chr);
298366
-
298366
-out:
298366
     s->timer_tag = 0;
298366
+    if (!s->connected) {
298366
+        /* Next poll ... */
298366
+        pty_chr_update_read_handler(chr);
298366
+    }
298366
     return FALSE;
298366
 }
298366