[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-trivial] [PULL 18/27] curl: Operate on zero-length file
From: |
Michael Tokarev |
Subject: |
[Qemu-trivial] [PULL 18/27] curl: Operate on zero-length file |
Date: |
Wed, 14 Sep 2016 10:58:44 +0300 |
From: Tomáš Golembiovský <address@hidden>
Another attempt to fix the bug 1596870.
When creating new disk backed by remote file accessed via HTTPS and the
backing file has zero length, qemu-img terminates with uniformative
error message:
qemu-img: disk.qcow2: CURL: Error opening file:
While it may not make much sense to operate on empty file, other block
backends (e.g. raw backend for regular files) seem to allow it. This
patch fixes it for the curl backend and improves the reported error.
Signed-off-by: Tomáš Golembiovský <address@hidden>
Signed-off-by: Michael Tokarev <address@hidden>
---
block/curl.c | 25 +++++++++++++++++++++----
1 file changed, 21 insertions(+), 4 deletions(-)
diff --git a/block/curl.c b/block/curl.c
index 426fb4d..571f24c 100644
--- a/block/curl.c
+++ b/block/curl.c
@@ -675,11 +675,28 @@ static int curl_open(BlockDriverState *bs, QDict
*options, int flags,
curl_easy_setopt(state->curl, CURLOPT_HEADERDATA, s);
if (curl_easy_perform(state->curl))
goto out;
- curl_easy_getinfo(state->curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &d);
- if (d)
- s->len = (size_t)d;
- else if(!s->len)
+ if (curl_easy_getinfo(state->curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &d)) {
goto out;
+ }
+ /* Prior CURL 7.19.4 return value of 0 could mean that the file size is not
+ * know or the size is zero. From 7.19.4 CURL returns -1 if size is not
+ * known and zero if it is realy zero-length file. */
+#if LIBCURL_VERSION_NUM >= 0x071304
+ if (d < 0) {
+ pstrcpy(state->errmsg, CURL_ERROR_SIZE,
+ "Server didn't report file size.");
+ goto out;
+ }
+#else
+ if (d <= 0) {
+ pstrcpy(state->errmsg, CURL_ERROR_SIZE,
+ "Unknown file size or zero-length file.");
+ goto out;
+ }
+#endif
+
+ s->len = (size_t)d;
+
if ((!strncasecmp(s->url, "http://", strlen("http://"))
|| !strncasecmp(s->url, "https://", strlen("https://")))
&& !s->accept_range) {
--
2.1.4
- [Qemu-trivial] [PULL 00/27] Trivial patches for 2016-09-14, Michael Tokarev, 2016/09/14
- [Qemu-trivial] [PULL 13/27] ivshmem: Delete duplicate debug message, Michael Tokarev, 2016/09/14
- [Qemu-trivial] [PULL 02/27] tcg: Remove duplicate header includes, Michael Tokarev, 2016/09/14
- [Qemu-trivial] [PULL 09/27] MAINTAINERS: Add some header files to the PC chipset section, Michael Tokarev, 2016/09/14
- [Qemu-trivial] [PULL 14/27] timer: update comments, Michael Tokarev, 2016/09/14
- [Qemu-trivial] [PULL 04/27] MAINTAINERS: Add include/hw/unicore32/ to UniCore32 section, Michael Tokarev, 2016/09/14
- [Qemu-trivial] [PULL 25/27] win32: don't run subprocess tests on Mingw32 platform, Michael Tokarev, 2016/09/14
- [Qemu-trivial] [PULL 06/27] MAINTAINERS: Add include/hw/sh4/ to SH4 section, Michael Tokarev, 2016/09/14
- [Qemu-trivial] [PULL 18/27] curl: Operate on zero-length file,
Michael Tokarev <=
- [Qemu-trivial] [PULL 22/27] tricore: remove useless cast, Michael Tokarev, 2016/09/14
- [Qemu-trivial] [PULL 01/27] Remove remainders of HPPA backend, Michael Tokarev, 2016/09/14
- [Qemu-trivial] [PULL 23/27] fw_cfg: remove useless casts, Michael Tokarev, 2016/09/14
- [Qemu-trivial] [PULL 07/27] MAINTAINERS: Add include/sysemu/cpus.h, Michael Tokarev, 2016/09/14
- [Qemu-trivial] [PULL 21/27] s390x: remove useless cast, Michael Tokarev, 2016/09/14
- [Qemu-trivial] [PULL 27/27] mptsas: change .realize function name, Michael Tokarev, 2016/09/14
- [Qemu-trivial] [PULL 03/27] ui/console: Fix non-working backspace key in monitor of gtk UI, Michael Tokarev, 2016/09/14
- [Qemu-trivial] [PULL 10/27] MAINTAINERS: Fix up F: entry bit rot, Michael Tokarev, 2016/09/14
- [Qemu-trivial] [PULL 26/27] linux-user/qemu.h: change malloc to g_malloc, free to g_free, Michael Tokarev, 2016/09/14
- [Qemu-trivial] [PULL 08/27] MAINTAINERS: Fix wildcard for scsi headers, Michael Tokarev, 2016/09/14