qemu-block
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-block] [PATCH] curl: Operate on zero-length file


From: Tomáš Golembiovský
Subject: [Qemu-block] [PATCH] curl: Operate on zero-length file
Date: Tue, 28 Jun 2016 12:37:34 +0200

This is an attempt to fix small 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.

Signed-off-by: Tomáš Golembiovský <address@hidden>
---
 block/curl.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/block/curl.c b/block/curl.c
index da9f5e8..ee6c5ea 100644
--- a/block/curl.c
+++ b/block/curl.c
@@ -675,11 +675,17 @@ 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;
+    }
+    if (d < 0) {
+        pstrcpy(state->errmsg, CURL_ERROR_SIZE,
+                "Received invalid file length.");
+        goto out;
+    }
+
+    s->len = (size_t)d;
+
     if ((!strncasecmp(s->url, "http://";, strlen("http://";))
         || !strncasecmp(s->url, "https://";, strlen("https://";)))
         && !s->accept_range) {
-- 
2.9.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]