From: Hanna Reitz <hreitz@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>, qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>, qemu-block@nongnu.org
Subject: Re: [PATCH] block/curl.c: Check error return from curl_easy_setopt()
Date: Tue, 1 Feb 2022 12:25:03 +0100 [thread overview]
Message-ID: <a26290d8-558c-ba85-ccf9-b56051a6dd75@redhat.com> (raw)
In-Reply-To: <20220128165535.2550899-1-peter.maydell@linaro.org>
On 28.01.22 17:55, Peter Maydell wrote:
> Coverity points out that we aren't checking the return value
> from curl_easy_setopt() for any of the calls to it we make
> in block/curl.c.
>
> Fixes: Coverity CID 1459336, 1459482, 1460331
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> Big fat disclaimer: tested only with 'make check', which I suspect
> may not be exercising this block backend. Hints on how to test
> more thoroughly are welcome.
>
> block/curl.c | 90 +++++++++++++++++++++++++++++++++-------------------
> 1 file changed, 58 insertions(+), 32 deletions(-)
One problem I see in general is that most of the setopt functions are
(indirectly) called from `curl_open()`, which is supposed to return an
error message. Its `out` label seems to expect some error description
in `state->errmsg`. The error handling here doesn’t set such a description.
Then again, there are enough existing error paths that don’t set this
description either, so it isn’t quite this patch’s duty to fix that
situation. I guess it would be nice if we had a wrapper for
`curl_easy_setopt()` with an `Error **` parameter, so we could easily
generate error messages that describe key and value (and then
`curl_init_state()` should have an `Error **` parameter, too).
But this patch doesn’t make anything worse than it already is, so that’d
rather be an idea for future clean-up.
> diff --git a/block/curl.c b/block/curl.c
> index 6a6cd729758..aaee1b17bef 100644
> --- a/block/curl.c
> +++ b/block/curl.c
[...]
> @@ -879,7 +902,10 @@ static void curl_setup_preadv(BlockDriverState *bs, CURLAIOCB *acb)
>
> snprintf(state->range, 127, "%" PRIu64 "-%" PRIu64, start, end);
> trace_curl_setup_preadv(acb->bytes, start, state->range);
> - curl_easy_setopt(state->curl, CURLOPT_RANGE, state->range);
> + if (curl_easy_setopt(state->curl, CURLOPT_RANGE, state->range)) {
> + curl_clean_state(state);
> + goto out;
I think we need to mark the request as failed by setting `acb->ret` to a
negative value (and probably also clear `state->acb[0]` like the error
path below does).
Hanna
> + }
>
> if (curl_multi_add_handle(s->multi, state->curl) != CURLM_OK) {
> state->acb[0] = NULL;
next prev parent reply other threads:[~2022-02-01 12:34 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-28 16:55 [PATCH] block/curl.c: Check error return from curl_easy_setopt() Peter Maydell
2022-01-28 17:50 ` Daniel P. Berrangé
2022-01-28 18:08 ` Peter Maydell
2022-02-01 11:25 ` Hanna Reitz [this message]
2022-02-21 19:45 ` Peter Maydell
2022-02-22 14:58 ` Hanna Reitz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a26290d8-558c-ba85-ccf9-b56051a6dd75@redhat.com \
--to=hreitz@redhat.com \
--cc=kwolf@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).