qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tests/qtest/libqtest.c: Check for setsockopt() failure
@ 2020-11-03 11:51 Peter Maydell
  2020-11-03 11:56 ` Paolo Bonzini
  0 siblings, 1 reply; 2+ messages in thread
From: Peter Maydell @ 2020-11-03 11:51 UTC (permalink / raw)
  To: qemu-devel; +Cc: Laurent Vivier, Paolo Bonzini, Thomas Huth

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



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] tests/qtest/libqtest.c: Check for setsockopt() failure
  2020-11-03 11:51 [PATCH] tests/qtest/libqtest.c: Check for setsockopt() failure Peter Maydell
@ 2020-11-03 11:56 ` Paolo Bonzini
  0 siblings, 0 replies; 2+ messages in thread
From: Paolo Bonzini @ 2020-11-03 11:56 UTC (permalink / raw)
  To: Peter Maydell, qemu-devel; +Cc: Laurent Vivier, Thomas Huth

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



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-11-03 11:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-11-03 11:51 [PATCH] tests/qtest/libqtest.c: Check for setsockopt() failure Peter Maydell
2020-11-03 11:56 ` Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).