]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
toaster: API CustomImageRecipe check the recipe name supplied is valid
authorMichael Wood <michael.g.wood@intel.com>
Tue, 2 Feb 2016 17:44:01 +0000 (17:44 +0000)
committerbrian avery <avery.brian@gmail.com>
Mon, 8 Feb 2016 20:48:14 +0000 (12:48 -0800)
Check that the name for a new CustomImageRecipe doesn't already exist in
the project or in the database of existing recipes (e.g. from the layer
index). Also restrict the characters entered for the recipe naming
convention.

Signed-off-by: Michael Wood <michael.g.wood@intel.com>
Signed-off-by: brian avery <avery.brian@gmail.com>
lib/toaster/toastergui/views.py

index 65b38d064504b4337cd938033270cc07c6a672a0..851e962c05f0d06f7a1a437bf31c0070dabb702c 100755 (executable)
@@ -2362,6 +2362,27 @@ if True:
 
         # create custom recipe
         try:
+
+            # Only allowed chars in name are a-z, 0-9 and -
+            if re.search(r'[^a-z|0-9|-]', request.POST["name"]):
+                return {"error": "invalid-name"}
+
+            # Are there any recipes with the name already?
+            for existing_recipe in Recipe.objects.filter(
+                name=request.POST["name"]):
+                try:
+                    ci = CustomImageRecipe.objects.get(pk=existing_recipe.pk)
+                    if ci.project == params["project"]:
+                        return {"error": "already-exists" }
+                    else:
+                        # It is a CustomImageRecipe but not in our project
+                        # this is fine so
+                        continue
+                except:
+                    # It isn't a CustomImageRecipe so is a recipe from
+                    # another source.
+                    return {"error": "already-exists" }
+
             # create layer 'Custom layer' and verion if needed
             layer = Layer.objects.get_or_create(
                 name="toaster-custom-images",