socket: don't attempt to reconnect a TCP socket in server mode
Commitc3767ed0ebintroduced a possible SEGV when using a socket chardev with server=on because it assumes that all TCP sockets are in client mode. This patch adds a check to only reconnect when in client mode. Cc: Lei Li <lilei@linux.vnet.ibm.com> Reported-by: Michael Roth <mdroth@linux.vnet.ibm.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> (cherry picked from commit455aa1e081) Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
This commit is contained in:
parent
82645b9e93
commit
5af6b07ab0
|
|
@ -2148,10 +2148,12 @@ static int tcp_chr_write(CharDriverState *chr, const uint8_t *buf, int len)
|
||||||
TCPCharDriver *s = chr->opaque;
|
TCPCharDriver *s = chr->opaque;
|
||||||
if (s->connected) {
|
if (s->connected) {
|
||||||
return send_all(s->fd, buf, len);
|
return send_all(s->fd, buf, len);
|
||||||
} else {
|
} else if (s->listen_fd == -1) {
|
||||||
/* (Re-)connect for unconnected writing */
|
/* (Re-)connect for unconnected writing */
|
||||||
tcp_chr_connect(chr);
|
tcp_chr_connect(chr);
|
||||||
return 0;
|
return 0;
|
||||||
|
} else {
|
||||||
|
return len;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue