From da5e1169183ca6eb6fb470dc32ed1bfc24d1d406 Mon Sep 17 00:00:00 2001 From: Vladimir Sementsov-Ogievskiy Date: Tue, 10 Sep 2019 10:59:43 +0300 Subject: [PATCH] util/qemu-sockets: fix keep_alive handling in inet_connect_saddr MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In "if (saddr->keep_alive) {" we may already be on error path, with invalid sock < 0. Fix it by returning error earlier. Reported-by: Coverity (CID 1405300) Fixes: aec21d31756cbd Suggested-by: Peter Maydell Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20190910075943.12977-1-vsementsov@virtuozzo.com> Reviewed-by: Daniel P. Berrangé Signed-off-by: Eric Blake --- util/qemu-sockets.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c index 98ff3a1cce..bcc06d0e01 100644 --- a/util/qemu-sockets.c +++ b/util/qemu-sockets.c @@ -461,12 +461,13 @@ int inet_connect_saddr(InetSocketAddress *saddr, Error **errp) } } + freeaddrinfo(res); + if (sock < 0) { error_propagate(errp, local_err); + return sock; } - freeaddrinfo(res); - if (saddr->keep_alive) { int val = 1; int ret = qemu_setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE,