diff mbox series

[v2,1/2] block/curl.c: Set error message string if curl_init_state() fails

Message ID 20220222152341.850419-2-peter.maydell@linaro.org
State Superseded
Headers show
Series block/curl: check error return from curl_easy_setopt() | expand

Commit Message

Peter Maydell Feb. 22, 2022, 3:23 p.m. UTC
In curl_open(), the 'out' label assumes that the state->errmsg string
has been set (either by curl_easy_perform() or by manually copying a
string into it); however if curl_init_state() fails we will jump to
that label without setting the string.  Add the missing error string
setup.

(We can't be specific about the cause of failure: the documentation
of curl_easy_init() just says "If this function returns NULL,
something went wrong".)

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 block/curl.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Philippe Mathieu-Daudé Feb. 22, 2022, 9:30 p.m. UTC | #1
On 22/2/22 16:23, Peter Maydell wrote:
> In curl_open(), the 'out' label assumes that the state->errmsg string
> has been set (either by curl_easy_perform() or by manually copying a
> string into it); however if curl_init_state() fails we will jump to
> that label without setting the string.  Add the missing error string
> setup.
> 
> (We can't be specific about the cause of failure: the documentation
> of curl_easy_init() just says "If this function returns NULL,
> something went wrong".)
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>   block/curl.c | 2 ++
>   1 file changed, 2 insertions(+)

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Hanna Reitz Feb. 24, 2022, 2:08 p.m. UTC | #2
On 22.02.22 16:23, Peter Maydell wrote:
> In curl_open(), the 'out' label assumes that the state->errmsg string
> has been set (either by curl_easy_perform() or by manually copying a
> string into it); however if curl_init_state() fails we will jump to
> that label without setting the string.  Add the missing error string
> setup.
>
> (We can't be specific about the cause of failure: the documentation
> of curl_easy_init() just says "If this function returns NULL,
> something went wrong".)
>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>   block/curl.c | 2 ++
>   1 file changed, 2 insertions(+)

Reviewed-by: Hanna Reitz <hreitz@redhat.com>
diff mbox series

Patch

diff --git a/block/curl.c b/block/curl.c
index 6a6cd729758..95168529715 100644
--- a/block/curl.c
+++ b/block/curl.c
@@ -759,6 +759,8 @@  static int curl_open(BlockDriverState *bs, QDict *options, int flags,
     // Get file size
 
     if (curl_init_state(s, state) < 0) {
+        pstrcpy(state->errmsg, CURL_ERROR_SIZE,
+                "curl library initialization failed.");
         goto out;
     }