[lxc-devel] [lxd/master] lxd/containers: Prevent duplicate profiles

stgraber on Github lxc-bot at linuxcontainers.org
Wed Nov 7 18:59:19 UTC 2018


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 354 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20181107/5c62d6f9/attachment.bin>
-------------- next part --------------
From 537509c792a12b915d7f7f126d5b360f22e095a5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Wed, 7 Nov 2018 13:58:58 -0500
Subject: [PATCH] lxd/containers: Prevent duplicate profiles
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd/container_lxc.go | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/lxd/container_lxc.go b/lxd/container_lxc.go
index 0bee5af638..9819bda540 100644
--- a/lxd/container_lxc.go
+++ b/lxd/container_lxc.go
@@ -3875,10 +3875,17 @@ func (c *containerLXC) Update(args db.ContainerArgs, userRequested bool) error {
 		return errors.Wrap(err, "Failed to get project profiles")
 	}
 
-	for _, name := range args.Profiles {
-		if !shared.StringInSlice(name, profiles) {
-			return fmt.Errorf("Profile doesn't exist: %s", name)
+	checkedProfiles := []string{}
+	for _, profile := range args.Profiles {
+		if !shared.StringInSlice(profile, profiles) {
+			return fmt.Errorf("Requested profile '%s' doesn't exist", profile)
 		}
+
+		if shared.StringInSlice(profile, checkedProfiles) {
+			return fmt.Errorf("Duplicate profile found in request")
+		}
+
+		checkedProfiles = append(checkedProfiles, profile)
 	}
 
 	// Validate the new architecture


More information about the lxc-devel mailing list