diff mbox series

[v2,1/2] elf2dmp: Check curl_easy_setopt() return value

Message ID 20210910170656.366592-2-philmd@redhat.com
State New
Headers show
Series [v2,1/2] elf2dmp: Check curl_easy_setopt() return value | expand

Commit Message

Philippe Mathieu-Daudé Sept. 10, 2021, 5:06 p.m. UTC
From: Peter Maydell <peter.maydell@linaro.org>


Coverity points out that we aren't checking the return value
from curl_easy_setopt().

Fixes: Coverity CID 1458895
Inspired-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>

---
Informal T-b tag on
https://lore.kernel.org/qemu-devel/20210909004313.1dadb24e@192.168.1.7/
Tested-by: Viktor Prutyanov <viktor.prutyanov@phystech.edu>


v1 from Peter:
https://lore.kernel.org/qemu-devel/20210901143910.17112-2-peter.maydell@linaro.org/
---
 contrib/elf2dmp/download.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)

-- 
2.31.1

Comments

Viktor Prutyanov Sept. 10, 2021, 5:17 p.m. UTC | #1
Hi,

On Fri, 10 Sep 2021 19:06:55 +0200
Philippe Mathieu-Daudé <philmd@redhat.com> wrote:

> From: Peter Maydell <peter.maydell@linaro.org>

> 

> Coverity points out that we aren't checking the return value

> from curl_easy_setopt().

> 

> Fixes: Coverity CID 1458895

> Inspired-by: Peter Maydell <peter.maydell@linaro.org>

> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>

> ---

> Informal T-b tag on

> https://lore.kernel.org/qemu-devel/20210909004313.1dadb24e@192.168.1.7/

> Tested-by: Viktor Prutyanov <viktor.prutyanov@phystech.edu>

> 

> v1 from Peter:

> https://lore.kernel.org/qemu-devel/20210901143910.17112-2-peter.maydell@linaro.org/

> ---

>  contrib/elf2dmp/download.c | 22 ++++++++++------------

>  1 file changed, 10 insertions(+), 12 deletions(-)

> 

> diff --git a/contrib/elf2dmp/download.c b/contrib/elf2dmp/download.c

> index d09e607431f..bd7650a7a27 100644

> --- a/contrib/elf2dmp/download.c

> +++ b/contrib/elf2dmp/download.c

> @@ -25,21 +25,19 @@ int download_url(const char *name, const char

> *url) goto out_curl;

>      }

>  

> -    curl_easy_setopt(curl, CURLOPT_URL, url);

> -    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL);

> -    curl_easy_setopt(curl, CURLOPT_WRITEDATA, file);

> -    curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);

> -    curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0);

> -

> -    if (curl_easy_perform(curl) != CURLE_OK) {

> -        err = 1;

> -        fclose(file);

> +    if (curl_easy_setopt(curl, CURLOPT_URL, url) != CURLE_OK

> +            || curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL)

> != CURLE_OK

> +            || curl_easy_setopt(curl, CURLOPT_WRITEDATA, file) !=

> CURLE_OK

> +            || curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1) !=

> CURLE_OK

> +            || curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0) !=

> CURLE_OK

> +            || curl_easy_perform(curl) != CURLE_OK) {

>          unlink(name);

> -        goto out_curl;

> +        fclose(file);

> +        err = 1;

> +    } else {

> +        err = fclose(file);

>      }

>  

> -    err = fclose(file);

> -

>  out_curl:

>      curl_easy_cleanup(curl);

>  


Reviewed-by: Viktor Prutyanov <viktor.prutyanov@phystech.edu>

Tested-by: Viktor Prutyanov <viktor.prutyanov@phystech.edu>


-- 
Viktor Prutyanov
diff mbox series

Patch

diff --git a/contrib/elf2dmp/download.c b/contrib/elf2dmp/download.c
index d09e607431f..bd7650a7a27 100644
--- a/contrib/elf2dmp/download.c
+++ b/contrib/elf2dmp/download.c
@@ -25,21 +25,19 @@  int download_url(const char *name, const char *url)
         goto out_curl;
     }
 
-    curl_easy_setopt(curl, CURLOPT_URL, url);
-    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL);
-    curl_easy_setopt(curl, CURLOPT_WRITEDATA, file);
-    curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
-    curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0);
-
-    if (curl_easy_perform(curl) != CURLE_OK) {
-        err = 1;
-        fclose(file);
+    if (curl_easy_setopt(curl, CURLOPT_URL, url) != CURLE_OK
+            || curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL) != CURLE_OK
+            || curl_easy_setopt(curl, CURLOPT_WRITEDATA, file) != CURLE_OK
+            || curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1) != CURLE_OK
+            || curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0) != CURLE_OK
+            || curl_easy_perform(curl) != CURLE_OK) {
         unlink(name);
-        goto out_curl;
+        fclose(file);
+        err = 1;
+    } else {
+        err = fclose(file);
     }
 
-    err = fclose(file);
-
 out_curl:
     curl_easy_cleanup(curl);