util/qemu-sockets: fix keep_alive handling in inet_connect_saddr
diff mbox series

Message ID 20190910075943.12977-1-vsementsov@virtuozzo.com
State New
Headers show
Series
  • util/qemu-sockets: fix keep_alive handling in inet_connect_saddr
Related show

Commit Message

Vladimir Sementsov-Ogievskiy Sept. 10, 2019, 7:59 a.m. UTC
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)
Suggested-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
 util/qemu-sockets.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Daniel P. Berrangé Sept. 10, 2019, 8:03 a.m. UTC | #1
On Tue, Sep 10, 2019 at 10:59:43AM +0300, Vladimir Sementsov-Ogievskiy wrote:
> 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)
> Suggested-by: Peter Maydell <peter.maydell@linaro.org>
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> ---
>  util/qemu-sockets.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>


Regards,
Daniel
Stefano Garzarella Sept. 10, 2019, 9:37 a.m. UTC | #2
On Tue, Sep 10, 2019 at 10:59:43AM +0300, Vladimir Sementsov-Ogievskiy wrote:
> 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)
> Suggested-by: Peter Maydell <peter.maydell@linaro.org>
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> ---
>  util/qemu-sockets.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)

Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Eric Blake Sept. 10, 2019, 1:59 p.m. UTC | #3
On 9/10/19 3:03 AM, Daniel P. Berrangé wrote:
> On Tue, Sep 10, 2019 at 10:59:43AM +0300, Vladimir Sementsov-Ogievskiy wrote:
>> 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)
>> Suggested-by: Peter Maydell <peter.maydell@linaro.org>
>> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
>> ---
>>  util/qemu-sockets.c | 5 +++--
>>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>

Thanks.  Will queue through my NBD tree, since that's where the original
problem was introduced.
Vladimir Sementsov-Ogievskiy Sept. 11, 2019, 12:08 p.m. UTC | #4
10.09.2019 16:59, Eric Blake wrote:
> On 9/10/19 3:03 AM, Daniel P. Berrangé wrote:
>> On Tue, Sep 10, 2019 at 10:59:43AM +0300, Vladimir Sementsov-Ogievskiy wrote:
>>> 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)
>>> Suggested-by: Peter Maydell <peter.maydell@linaro.org>
>>> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
>>> ---
>>>   util/qemu-sockets.c | 5 +++--
>>>   1 file changed, 3 insertions(+), 2 deletions(-)
>>
>> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
> 
> Thanks.  Will queue through my NBD tree, since that's where the original
> problem was introduced.
> 

Please add when queueing:

Fixes: aec21d31756cbd
Vladimir Sementsov-Ogievskiy Sept. 25, 2019, 11:33 a.m. UTC | #5
11.09.2019 15:08, Vladimir Sementsov-Ogievskiy wrote:
> 10.09.2019 16:59, Eric Blake wrote:
>> On 9/10/19 3:03 AM, Daniel P. Berrangé wrote:
>>> On Tue, Sep 10, 2019 at 10:59:43AM +0300, Vladimir Sementsov-Ogievskiy wrote:
>>>> 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)
>>>> Suggested-by: Peter Maydell <peter.maydell@linaro.org>
>>>> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
>>>> ---
>>>>   util/qemu-sockets.c | 5 +++--
>>>>   1 file changed, 3 insertions(+), 2 deletions(-)
>>>
>>> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
>>
>> Thanks.  Will queue through my NBD tree, since that's where the original
>> problem was introduced.
>>
> 
> Please add when queueing:
> 
> Fixes: aec21d31756cbd
> 

Hmm, don't you forget? Don't see it neither in pull request nor in your branches.
Eric Blake Sept. 25, 2019, 1:13 p.m. UTC | #6
On 9/25/19 6:33 AM, Vladimir Sementsov-Ogievskiy wrote:
> 11.09.2019 15:08, Vladimir Sementsov-Ogievskiy wrote:
>> 10.09.2019 16:59, Eric Blake wrote:
>>> On 9/10/19 3:03 AM, Daniel P. Berrangé wrote:
>>>> On Tue, Sep 10, 2019 at 10:59:43AM +0300, Vladimir Sementsov-Ogievskiy wrote:
>>>>> 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)
>>>>> Suggested-by: Peter Maydell <peter.maydell@linaro.org>
>>>>> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
>>>>> ---
>>>>>   util/qemu-sockets.c | 5 +++--
>>>>>   1 file changed, 3 insertions(+), 2 deletions(-)
>>>>
>>>> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
>>>
>>> Thanks.  Will queue through my NBD tree, since that's where the original
>>> problem was introduced.
>>>
>>
>> Please add when queueing:
>>
>> Fixes: aec21d31756cbd
>>
> 
> Hmm, don't you forget? Don't see it neither in pull request nor in your branches.

Thanks for catching this.  Fixing now...

Patch
diff mbox series

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,