[lxc-devel] [lxd/master] lxd/daemon_images: avoid null deref

brauner on Github lxc-bot at linuxcontainers.org
Sun Sep 18 00:32:12 UTC 2016


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 1180 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20160918/a972ce98/attachment.bin>
-------------- next part --------------
From f94a22a042fe8123b4d0c58d0c44202cea5c9bb4 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at canonical.com>
Date: Sun, 18 Sep 2016 02:25:33 +0200
Subject: [PATCH] lxd/daemon_images: avoid null deref

Signed-off-by: Christian Brauner <christian.brauner at canonical.com>
---
 lxd/daemon_images.go | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/lxd/daemon_images.go b/lxd/daemon_images.go
index c589f7a..b7ea919 100644
--- a/lxd/daemon_images.go
+++ b/lxd/daemon_images.go
@@ -29,6 +29,7 @@ var imageStreamCacheLock sync.Mutex
 func (d *Daemon) ImageDownload(op *operation, server string, protocol string, certificate string, secret string, alias string, forContainer bool, autoUpdate bool) (string, error) {
 	var err error
 	var ss *shared.SimpleStreams
+	var ctxMap log.Ctx
 
 	if protocol == "" {
 		protocol = "lxd"
@@ -114,9 +115,13 @@ func (d *Daemon) ImageDownload(op *operation, server string, protocol string, ce
 
 	d.imagesDownloadingLock.RUnlock()
 
-	shared.LogInfo(
-		"Downloading image",
-		log.Ctx{"trigger": op.url, "image": fp, "operation": op.id, "alias": alias, "server": server})
+	if op == nil {
+		ctxMap = log.Ctx{"alias": alias, "server": server}
+	} else {
+		ctxMap = log.Ctx{"trigger": op.url, "image": fp, "operation": op.id, "alias": alias, "server": server}
+	}
+
+	shared.LogInfo("Downloading image", ctxMap)
 
 	// Add the download to the queue
 	d.imagesDownloadingLock.Lock()
@@ -233,9 +238,7 @@ func (d *Daemon) ImageDownload(op *operation, server string, protocol string, ce
 			}
 		}
 
-		shared.LogInfo(
-			"Image downloaded",
-			log.Ctx{"image": fp, "fingerprint": fp, "operation": op.id, "alias": alias, "server": server})
+		shared.LogInfo("Image downloaded", ctxMap)
 
 		if forContainer {
 			return fp, dbImageLastAccessInit(d.db, fp)
@@ -401,9 +404,7 @@ func (d *Daemon) ImageDownload(op *operation, server string, protocol string, ce
 		}
 	}
 
-	shared.LogInfo(
-		"Image downloaded",
-		log.Ctx{"image": fp, "operation": op.id, "alias": alias, "server": server})
+	shared.LogInfo("Image downloaded", ctxMap)
 
 	if forContainer {
 		return fp, dbImageLastAccessInit(d.db, fp)


More information about the lxc-devel mailing list