[lxc-devel] [go-lxc/v2] Container: Check container isn't nil when checking state

tomponline on Github lxc-bot at linuxcontainers.org
Wed Aug 26 14:52:30 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 374 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200826/8577f095/attachment.bin>
-------------- next part --------------
From 70331db540ebc4a30247e6d8e4ef2c6330375f18 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Wed, 26 Aug 2020 15:51:00 +0100
Subject: [PATCH 1/2] container: Check c.container isn't nil to protect against
 crash

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 container.go | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/container.go b/container.go
index eb8a415..8c8da83 100644
--- a/container.go
+++ b/container.go
@@ -279,6 +279,10 @@ func (c *Container) Snapshots() ([]Snapshot, error) {
 
 // Caller needs to hold the lock
 func (c *Container) state() State {
+	if c.container == nil {
+		return StateMap["STOPPED"]
+	}
+
 	return StateMap[C.GoString(C.go_lxc_state(c.container))]
 }
 

From 762f161f646758e7d61a85a0f23ad5faa8840664 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Wed, 26 Aug 2020 15:51:19 +0100
Subject: [PATCH 2/2] container: golint

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 container.go | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/container.go b/container.go
index 8c8da83..7a9c5d5 100644
--- a/container.go
+++ b/container.go
@@ -1991,20 +1991,20 @@ func buildBdevSpecs(o *BackendStoreSpecs) *C.struct_bdev_specs {
 
 	if o.FSType != "" {
 		fstype := C.CString(o.FSType)
-		specs.fstype = fstype 
+		specs.fstype = fstype
 		defer C.free(unsafe.Pointer(fstype))
 	}
 
-	if o.FSSize > 0  {
+	if o.FSSize > 0 {
 		specs.fssize = C.uint64_t(o.FSSize)
 	}
 
-	if o.ZFS.Root != "" { 
+	if o.ZFS.Root != "" {
 		zfsroot := C.CString(o.ZFS.Root)
 		specs.zfs.zfsroot = zfsroot
 		defer C.free(unsafe.Pointer(zfsroot))
 	}
-	
+
 	if o.LVM.VG != "" {
 		vg := C.CString(o.LVM.VG)
 		specs.lvm.vg = vg


More information about the lxc-devel mailing list