The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/7605

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===
Closes #7604

Signed-off-by: Stéphane Graber <stgra...@ubuntu.com>
From e1edf577e4e1a76750233d166fcec137d4fd5d27 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgra...@ubuntu.com>
Date: Wed, 1 Jul 2020 15:08:43 -0400
Subject: [PATCH] lxd/project: Add more name checks
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Closes #7604

Signed-off-by: Stéphane Graber <stgra...@ubuntu.com>
---
 lxd/api_project.go | 46 ++++++++++++++++++++++++++++++++--------------
 1 file changed, 32 insertions(+), 14 deletions(-)

diff --git a/lxd/api_project.go b/lxd/api_project.go
index 38491e9775..5a95f71ab5 100644
--- a/lxd/api_project.go
+++ b/lxd/api_project.go
@@ -112,20 +112,9 @@ func projectsPost(d *Daemon, r *http.Request) 
response.Response {
        }
 
        // Sanity checks
-       if project.Name == "" {
-               return response.BadRequest(fmt.Errorf("No name provided"))
-       }
-
-       if strings.Contains(project.Name, "/") {
-               return response.BadRequest(fmt.Errorf("Project names may not 
contain slashes"))
-       }
-
-       if project.Name == "*" {
-               return response.BadRequest(fmt.Errorf("Reserved project name"))
-       }
-
-       if shared.StringInSlice(project.Name, []string{".", ".."}) {
-               return response.BadRequest(fmt.Errorf("Invalid project name 
'%s'", project.Name))
+       err = projectValidateName(project.Name)
+       if err != nil {
+               return response.BadRequest(err)
        }
 
        // Validate the configuration
@@ -442,6 +431,11 @@ func projectPost(d *Daemon, r *http.Request) 
response.Response {
                                return errors.Wrapf(err, "Fetch project id %q", 
name)
                        }
 
+                       err = projectValidateName(name)
+                       if err != nil {
+                               return err
+                       }
+
                        return tx.RenameProject(name, req.Name)
                })
                if err != nil {
@@ -576,3 +570,27 @@ func projectValidateConfig(config map[string]string) error 
{
 
        return nil
 }
+
+func projectValidateName(name string) error {
+       if name == "" {
+               return fmt.Errorf("No name provided")
+       }
+
+       if strings.Contains(name, "/") {
+               return fmt.Errorf("Project names may not contain slashes")
+       }
+
+       if strings.Contains(name, " ") {
+               return fmt.Errorf("Project names may not contain spaces")
+       }
+
+       if name == "*" {
+               return fmt.Errorf("Reserved project name")
+       }
+
+       if shared.StringInSlice(name, []string{".", ".."}) {
+               return fmt.Errorf("Invalid project name '%s'", name)
+       }
+
+       return nil
+}
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to