block/curl: Fix return value from curl_read_cb
While commit 38bbc0a580
is correct in that
the callback is supposed to return the number of bytes handled; what it
does not mention is that libcurl will throw an error if the callback did
not "handle" all of the data passed to it.
Therefore, if the callback receives some data that it cannot handle
(either because the receive buffer has not been set up yet or because it
would not fit into the receive buffer) and we have to ignore it, we
still have to report that the data has been handled.
Obviously, this should not happen normally. But it does happen at least
for FTP connections where some data (that we do not expect) may be
generated when the connection is established.
Cc: qemu-stable@nongnu.org
Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-id: 20161025025431.24714-3-mreitz@redhat.com
Signed-off-by: Jeff Cody <jcody@redhat.com>
This commit is contained in:
parent
9054d9f6b0
commit
4e7676571b
11
block/curl.c
11
block/curl.c
@ -211,12 +211,13 @@ static size_t curl_read_cb(void *ptr, size_t size, size_t nmemb, void *opaque)
|
|||||||
|
|
||||||
DPRINTF("CURL: Just reading %zd bytes\n", realsize);
|
DPRINTF("CURL: Just reading %zd bytes\n", realsize);
|
||||||
|
|
||||||
if (!s || !s->orig_buf)
|
if (!s || !s->orig_buf) {
|
||||||
return 0;
|
goto read_end;
|
||||||
|
}
|
||||||
|
|
||||||
if (s->buf_off >= s->buf_len) {
|
if (s->buf_off >= s->buf_len) {
|
||||||
/* buffer full, read nothing */
|
/* buffer full, read nothing */
|
||||||
return 0;
|
goto read_end;
|
||||||
}
|
}
|
||||||
realsize = MIN(realsize, s->buf_len - s->buf_off);
|
realsize = MIN(realsize, s->buf_len - s->buf_off);
|
||||||
memcpy(s->orig_buf + s->buf_off, ptr, realsize);
|
memcpy(s->orig_buf + s->buf_off, ptr, realsize);
|
||||||
@ -237,7 +238,9 @@ static size_t curl_read_cb(void *ptr, size_t size, size_t nmemb, void *opaque)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return realsize;
|
read_end:
|
||||||
|
/* curl will error out if we do not return this value */
|
||||||
|
return size * nmemb;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int curl_find_buf(BDRVCURLState *s, size_t start, size_t len,
|
static int curl_find_buf(BDRVCURLState *s, size_t start, size_t len,
|
||||||
|
Loading…
Reference in New Issue
Block a user