Coverity-CWE 476: NULL Pointer Dereference (137978 Bad use of null-like value) 04/13304/3
authork4.rahul <rahul.k4@tataelxsi.co.in>
Thu, 27 Apr 2023 10:50:47 +0000 (16:20 +0530)
committerGulsum Atici <gulsum.atici@canonical.com>
Mon, 8 May 2023 14:40:38 +0000 (17:40 +0300)
Coverity fix for Bad use of null-like value

Change-Id: I7437c2b2aeeff25619b5405bcd7c962f3fbd70bb
Signed-off-by: k4.rahul <rahul.k4@tataelxsi.co.in>
osm_common/dbmemory.py
releasenotes/notes/cwe_476-c132043815560a45.yaml [new file with mode: 0644]

index 272f6d6..e72db5b 100644 (file)
@@ -126,26 +126,27 @@ class DbMemory(DbBase):
                 for content_item in content:
                     if key_list[key_next_index] == "ANYINDEX" and isinstance(v, dict):
                         matches = True
-                        for k2, v2 in target.items():
-                            k_new_list = k2.split(".")
-                            new_operator = "eq"
-                            if k_new_list[-1] in (
-                                "eq",
-                                "ne",
-                                "gt",
-                                "gte",
-                                "lt",
-                                "lte",
-                                "cont",
-                                "ncont",
-                                "neq",
-                            ):
-                                new_operator = k_new_list.pop()
-                            if not recursive_find(
-                                k_new_list, 0, content_item, new_operator, v2
-                            ):
-                                matches = False
-                                break
+                        if target:
+                            for k2, v2 in target.items():
+                                k_new_list = k2.split(".")
+                                new_operator = "eq"
+                                if k_new_list[-1] in (
+                                    "eq",
+                                    "ne",
+                                    "gt",
+                                    "gte",
+                                    "lt",
+                                    "lte",
+                                    "cont",
+                                    "ncont",
+                                    "neq",
+                                ):
+                                    new_operator = k_new_list.pop()
+                                if not recursive_find(
+                                    k_new_list, 0, content_item, new_operator, v2
+                                ):
+                                    matches = False
+                                    break
 
                     else:
                         matches = recursive_find(
diff --git a/releasenotes/notes/cwe_476-c132043815560a45.yaml b/releasenotes/notes/cwe_476-c132043815560a45.yaml
new file mode 100644 (file)
index 0000000..3a1966b
--- /dev/null
@@ -0,0 +1,22 @@
+#######################################################################################
+# 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-CWE 476: NULL Pointer Dereference (137978 Bad use of null-like value)
+    Coverity fix for Bad use of null-like value
+