[PATCH] tests/qtest/libqtest.c: Check for setsockopt() failure

Peter Maydell posted 1 patch 3 years, 6 months ago
Test checkpatch passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20201103115112.19211-1-peter.maydell@linaro.org
Maintainers: Paolo Bonzini <pbonzini@redhat.com>, Laurent Vivier <lvivier@redhat.com>, Thomas Huth <thuth@redhat.com>
tests/qtest/libqtest.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
[PATCH] tests/qtest/libqtest.c: Check for setsockopt() failure
Posted by Peter Maydell 3 years, 6 months ago
In socket_accept() we use setsockopt() to set SO_RCVTIMEO,
but we don't check the return value for failure. Do so.

Fixes: Coverity CID 1432321
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 tests/qtest/libqtest.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
index 99deff47efc..be0fb430ddd 100644
--- a/tests/qtest/libqtest.c
+++ b/tests/qtest/libqtest.c
@@ -110,8 +110,13 @@ static int socket_accept(int sock)
     struct timeval timeout = { .tv_sec = SOCKET_TIMEOUT,
                                .tv_usec = 0 };
 
-    setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (void *)&timeout,
-               sizeof(timeout));
+    if (qemu_setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO,
+                        (void *)&timeout, sizeof(timeout))) {
+        fprintf(stderr, "%s failed to set SO_RCVTIMEO: %s\n",
+                __func__, strerror(errno));
+        close(sock);
+        return -1;
+    }
 
     do {
         addrlen = sizeof(addr);
-- 
2.20.1


Re: [PATCH] tests/qtest/libqtest.c: Check for setsockopt() failure
Posted by Paolo Bonzini 3 years, 6 months ago
On 03/11/20 12:51, Peter Maydell wrote:
> In socket_accept() we use setsockopt() to set SO_RCVTIMEO,
> but we don't check the return value for failure. Do so.
> 
> Fixes: Coverity CID 1432321
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>  tests/qtest/libqtest.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
> index 99deff47efc..be0fb430ddd 100644
> --- a/tests/qtest/libqtest.c
> +++ b/tests/qtest/libqtest.c
> @@ -110,8 +110,13 @@ static int socket_accept(int sock)
>      struct timeval timeout = { .tv_sec = SOCKET_TIMEOUT,
>                                 .tv_usec = 0 };
>  
> -    setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (void *)&timeout,
> -               sizeof(timeout));
> +    if (qemu_setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO,
> +                        (void *)&timeout, sizeof(timeout))) {
> +        fprintf(stderr, "%s failed to set SO_RCVTIMEO: %s\n",
> +                __func__, strerror(errno));
> +        close(sock);
> +        return -1;
> +    }
>  
>      do {
>          addrlen = sizeof(addr);
> 


Queued, thanks.

Paolo