Coverity CWE 476: NULL Pointer Dereference 21/13321/7
authorelumalai <deepika.e@tataelxsi.co.in>
Fri, 28 Apr 2023 11:33:07 +0000 (17:03 +0530)
committeraticig <gulsum.atici@canonical.com>
Sun, 11 Jun 2023 16:56:50 +0000 (18:56 +0200)
Added fixes for NULL Pointer Dereference Coverity Issue

Change-Id: I2c68ff720f563631fba3ea8586e325a163d752c6
Signed-off-by: elumalai <deepika.e@tataelxsi.co.in>
NG-RO/osm_ng_ro/ns.py
NG-RO/osm_ng_ro/ro_main.py
releasenotes/notes/Coverity_NULL_Pointer_Dereference-59edb2d63f10c925.yaml [new file with mode: 0644]

index 75bae1b..cd75025 100644 (file)
@@ -2370,7 +2370,7 @@ class Ns(object):
         for target_vnf in target_list:
             # Find this VNF in the list from DB, raise exception if vnfInstanceId is not found
             vnfr_id = target_vnf["vnfInstanceId"]
-            existing_vnf = db_vnfrs.get(vnfr_id)
+            existing_vnf = db_vnfrs.get(vnfr_id, {})
             db_record = "vnfrs:{}:{}".format(vnfr_id, db_path)
             # vim_account_id = existing_vnf.get("vim-account-id", "")
 
@@ -2390,16 +2390,17 @@ class Ns(object):
                 # For single session VDU count-indes is 0
                 count_index = target_vdu.get("count-index", 0)
                 item_index = 0
-                existing_instance = None
-                for instance in existing_vnf.get("vdur", None):
-                    if (
-                        instance["vdu-name"] == vdu_name
-                        and instance["count-index"] == count_index
-                    ):
-                        existing_instance = instance
-                        break
-                    else:
-                        item_index += 1
+                existing_instance = {}
+                if existing_vnf:
+                    for instance in existing_vnf.get("vdur", {}):
+                        if (
+                            instance["vdu-name"] == vdu_name
+                            and instance["count-index"] == count_index
+                        ):
+                            existing_instance = instance
+                            break
+                        else:
+                            item_index += 1
 
                 target_record_id = "{}.{}".format(db_record, existing_instance["id"])
 
index f67d1cb..c0e47ae 100644 (file)
@@ -687,7 +687,7 @@ class Server(object):
         **kwargs,
     ):
         token_info = None
-        outdata = None
+        outdata = {}
         _format = None
         method = "DONE"
         rollback = []
diff --git a/releasenotes/notes/Coverity_NULL_Pointer_Dereference-59edb2d63f10c925.yaml b/releasenotes/notes/Coverity_NULL_Pointer_Dereference-59edb2d63f10c925.yaml
new file mode 100644 (file)
index 0000000..0ce7707
--- /dev/null
@@ -0,0 +1,20 @@
+#######################################################################################
+# Copyright ETSI Contributors and Others.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#######################################################################################
+---
+security:
+  - |
+    Coverity fix for issue CWE 476: NULL Pointer Dereference