carlwgeorge / rpms / qemu

Forked from rpms/qemu a year ago
Clone
5544c1b
From 40874e295225675fec7b42bb8e015fb3f2065a69 Mon Sep 17 00:00:00 2001
5544c1b
From: Anthony Liguori <aliguori@us.ibm.com>
5544c1b
Date: Wed, 5 Sep 2012 13:52:49 -0500
5544c1b
Subject: [PATCH] socket: don't attempt to reconnect a TCP socket in server
5544c1b
 mode
5544c1b
5544c1b
Commit c3767ed0eb5d0bb25fe409ae5dec06e3411ff1b6 introduced a possible SEGV when
5544c1b
using a socket chardev with server=on because it assumes that all TCP sockets
5544c1b
are in client mode.
5544c1b
5544c1b
This patch adds a check to only reconnect when in client mode.
5544c1b
5544c1b
Cc: Lei Li <lilei@linux.vnet.ibm.com>
5544c1b
Reported-by: Michael Roth <mdroth@linux.vnet.ibm.com>
5544c1b
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
5544c1b
(cherry picked from commit 455aa1e0818653c41fd794435b982426ce21ba2f)
5544c1b
5544c1b
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
5544c1b
---
5544c1b
 qemu-char.c | 4 +++-
5544c1b
 1 file changed, 3 insertions(+), 1 deletion(-)
5544c1b
5544c1b
diff --git a/qemu-char.c b/qemu-char.c
5544c1b
index 398baf1..767da93 100644
5544c1b
--- a/qemu-char.c
5544c1b
+++ b/qemu-char.c
5544c1b
@@ -2148,10 +2148,12 @@ static int tcp_chr_write(CharDriverState *chr, const uint8_t *buf, int len)
5544c1b
     TCPCharDriver *s = chr->opaque;
5544c1b
     if (s->connected) {
5544c1b
         return send_all(s->fd, buf, len);
5544c1b
-    } else {
5544c1b
+    } else if (s->listen_fd == -1) {
5544c1b
         /* (Re-)connect for unconnected writing */
5544c1b
         tcp_chr_connect(chr);
5544c1b
         return 0;
5544c1b
+    } else {
5544c1b
+        return len;
5544c1b
     }
5544c1b
 }
5544c1b
 
5544c1b
-- 
5544c1b
1.7.12.1
5544c1b