render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
3e5111
From 046e5f4d9cf163ec2f38ba201c7d4cbe7965d792 Mon Sep 17 00:00:00 2001
3e5111
Message-Id: <046e5f4d9cf163ec2f38ba201c7d4cbe7965d792@dist-git>
3e5111
From: Peter Krempa <pkrempa@redhat.com>
3e5111
Date: Tue, 20 Jun 2017 10:22:40 +0200
3e5111
Subject: [PATCH] util: storage: Report errors when source host data is missing
3e5111
3e5111
Merge the reporting of the missing source host data into the parser
3e5111
functions so that callers don't have to do it separately.
3e5111
3e5111
(cherry picked from commit 299aff7e0cd52c50da518eeed676144d373e9281)
3e5111
3e5111
https://bugzilla.redhat.com/show_bug.cgi?id=1461638
3e5111
3e5111
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
3e5111
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
3e5111
---
3e5111
 src/util/virstoragefile.c | 29 +++++++++++++++++++++++------
3e5111
 1 file changed, 23 insertions(+), 6 deletions(-)
3e5111
3e5111
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
3e5111
index f67e714e3c..3f8bc43928 100644
3e5111
--- a/src/util/virstoragefile.c
3e5111
+++ b/src/util/virstoragefile.c
3e5111
@@ -2803,8 +2803,18 @@ static int
3e5111
 virStorageSourceParseBackingJSONInetSocketAddress(virStorageNetHostDefPtr host,
3e5111
                                                   virJSONValuePtr json)
3e5111
 {
3e5111
-    const char *hostname = virJSONValueObjectGetString(json, "host");
3e5111
-    const char *port = virJSONValueObjectGetString(json, "port");
3e5111
+    const char *hostname;
3e5111
+    const char *port;
3e5111
+
3e5111
+    if (!json) {
3e5111
+        virReportError(VIR_ERR_INVALID_ARG, "%s",
3e5111
+                       _("missing remote server specification in JSON "
3e5111
+                         "backing volume definition"));
3e5111
+        return -1;
3e5111
+    }
3e5111
+
3e5111
+    hostname = virJSONValueObjectGetString(json, "host");
3e5111
+    port = virJSONValueObjectGetString(json, "port");
3e5111
 
3e5111
     if (!hostname) {
3e5111
         virReportError(VIR_ERR_INVALID_ARG, "%s",
3e5111
@@ -2827,10 +2837,17 @@ static int
3e5111
 virStorageSourceParseBackingJSONSocketAddress(virStorageNetHostDefPtr host,
3e5111
                                               virJSONValuePtr json)
3e5111
 {
3e5111
-    const char *type = virJSONValueObjectGetString(json, "type");
3e5111
-    const char *socket = virJSONValueObjectGetString(json, "socket");
3e5111
+    const char *type;
3e5111
+    const char *socket;
3e5111
 
3e5111
-    if (!type) {
3e5111
+    if (!json) {
3e5111
+        virReportError(VIR_ERR_INVALID_ARG, "%s",
3e5111
+                       _("missing remote server specification in JSON "
3e5111
+                         "backing volume definition"));
3e5111
+        return -1;
3e5111
+    }
3e5111
+
3e5111
+    if (!(type = virJSONValueObjectGetString(json, "type"))) {
3e5111
         virReportError(VIR_ERR_INVALID_ARG, "%s",
3e5111
                        _("missing socket address type in "
3e5111
                          "JSON backing volume definition"));
3e5111
@@ -2843,7 +2860,7 @@ virStorageSourceParseBackingJSONSocketAddress(virStorageNetHostDefPtr host,
3e5111
     } else if (STREQ(type, "unix")) {
3e5111
         host->transport = VIR_STORAGE_NET_HOST_TRANS_UNIX;
3e5111
 
3e5111
-        if (!socket) {
3e5111
+        if (!(socket = virJSONValueObjectGetString(json, "socket"))) {
3e5111
             virReportError(VIR_ERR_INVALID_ARG, "%s",
3e5111
                            _("missing socket path for udp backing server in "
3e5111
                              "JSON backing volume definition"));
3e5111
-- 
3e5111
2.13.1
3e5111