[lxc-devel] [lxd/master] lxc: Fix import crash when adding properties

stgraber on Github lxc-bot at linuxcontainers.org
Sat Sep 16 22:34:41 UTC 2017


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 370 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20170916/491288f1/attachment.bin>
-------------- next part --------------
From 549a2bedaac57a48e54f46d73bea92fa2de74ccd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Sat, 16 Sep 2017 15:29:11 -0700
Subject: [PATCH] lxc: Fix import crash when adding properties
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Closes #3803

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxc/image.go         | 4 ++++
 test/suites/basic.sh | 3 +++
 2 files changed, 7 insertions(+)

diff --git a/lxc/image.go b/lxc/image.go
index 394da38aa..ef6593231 100644
--- a/lxc/image.go
+++ b/lxc/image.go
@@ -686,6 +686,10 @@ func (c *imageCmd) run(conf *config.Config, args []string) error {
 				return fmt.Errorf(i18n.G("Bad property: %s"), entry)
 			}
 
+			if image.Properties == nil {
+				image.Properties = map[string]string{}
+			}
+
 			image.Properties[strings.TrimSpace(fields[0])] = strings.TrimSpace(fields[1])
 		}
 
diff --git a/test/suites/basic.sh b/test/suites/basic.sh
index cb2fef966..b8d84f193 100644
--- a/test/suites/basic.sh
+++ b/test/suites/basic.sh
@@ -42,6 +42,9 @@ test_basic_usage() {
 
   # Re-import the image
   mv "${LXD_DIR}/${sum}.tar.xz" "${LXD_DIR}/testimage.tar.xz"
+  lxc image import "${LXD_DIR}/testimage.tar.xz" --alias testimage user.foo=bar
+  lxc image show testimage | grep -q "user.foo: bar"
+  lxc image delete testimage
   lxc image import "${LXD_DIR}/testimage.tar.xz" --alias testimage
   rm "${LXD_DIR}/testimage.tar.xz"
 


More information about the lxc-devel mailing list