Changed code to not construct the path from user-controlled data. 05/129405/6
authorsharath reddy <bs.reddy@huawei.com>
Thu, 26 May 2022 13:37:03 +0000 (19:07 +0530)
committersharath reddy <bs.reddy@huawei.com>
Wed, 1 Jun 2022 08:56:44 +0000 (14:26 +0530)
Issue-ID: VNFSDK-834

Signed-off-by: sharath reddy <bs.reddy@huawei.com>
Change-Id: If9eb5ee546436ed9c4495bac8706883ee1ca98ce
Signed-off-by: sharath reddy <bs.reddy@huawei.com>
vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/scenario/VTPScenarioResource.java
vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vtp/VTPScenarioResourceTest.java

index 915cd14..1a8de34 100644 (file)
@@ -431,8 +431,12 @@ public class VTPScenarioResource extends VTPResource{
         }
 
         try {
-            FileUtils.deleteQuietly(new File(VTP_YAML_STORE, scenarioName));
-            FileUtils.deleteDirectory(scenarioDir);
+            if(FileUtils.directoryContains(new File(VTP_YAML_STORE), new File(scenarioName))) {
+                FileUtils.deleteQuietly(new File(VTP_YAML_STORE, scenarioName));
+            }
+            if(FileUtils.directoryContains(new File(VTP_YAML_STORE), scenarioDir)) {
+                FileUtils.deleteDirectory(scenarioDir);
+            }
         } catch (IOException e) {
             LOG.error("Delete scenario yaml {} failed", scenarioName, e);
             throw new VTPException(
index 5545779..b743615 100644 (file)
@@ -108,9 +108,11 @@ public class VTPScenarioResourceTest {
     @Test
     public void testDeleteScenario() throws Exception
     {
+        String yamlStore = vtpScenarioResource.VTP_YAML_STORE;
+        vtpScenarioResource.VTP_YAML_STORE = "/tmp";
         vtpScenarioResource.deleteScenario("demo-registry.yaml");
+        vtpScenarioResource.VTP_YAML_STORE = yamlStore;
     }
-
     @Test(expected = NullPointerException.class)
     public void testStorageTestcases() throws Exception
     {