From b2d732a70efa33e4bc478d351d64bc4adb4ea332 Mon Sep 17 00:00:00 2001 From: "k4.rahul" Date: Thu, 27 Apr 2023 16:20:47 +0530 Subject: [PATCH] Coverity-CWE 476: NULL Pointer Dereference (137978 Bad use of null-like value) Coverity fix for Bad use of null-like value Change-Id: I7437c2b2aeeff25619b5405bcd7c962f3fbd70bb Signed-off-by: k4.rahul --- osm_common/dbmemory.py | 41 ++++++++++--------- .../notes/cwe_476-c132043815560a45.yaml | 22 ++++++++++ 2 files changed, 43 insertions(+), 20 deletions(-) create mode 100644 releasenotes/notes/cwe_476-c132043815560a45.yaml diff --git a/osm_common/dbmemory.py b/osm_common/dbmemory.py index 272f6d6..e72db5b 100644 --- a/osm_common/dbmemory.py +++ b/osm_common/dbmemory.py @@ -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 index 0000000..3a1966b --- /dev/null +++ b/releasenotes/notes/cwe_476-c132043815560a45.yaml @@ -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 + -- 2.25.1