Skip to content

Commit a6287f1

Browse files
mbrinkhoffgreenbonebot
authored andcommitted
Fix: Invalid CVE configurations data for node schema
1 parent a53d2e9 commit a6287f1

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

pontos/models/__init__.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# SPDX-License-Identifier: GPL-3.0-or-later
44
#
55

6+
import logging
67
from dataclasses import dataclass
78
from datetime import date, datetime, timezone
89
from inspect import isclass
@@ -20,6 +21,8 @@
2021
"dotted_attributes",
2122
)
2223

24+
logger = logging.getLogger(__name__)
25+
2326

2427
class ModelError(PontosError):
2528
"""
@@ -149,10 +152,18 @@ def from_dict(cls, data: Dict[str, Any]):
149152
model_field_cls = type_hints.get(name)
150153
value = _get_value(model_field_cls, value) # type: ignore # pylint: disable=line-too-long # noqa: E501,PLW2901
151154
except (ValueError, TypeError) as e:
152-
raise ModelError(
153-
f"Error while creating {cls.__name__} model. Could not set "
154-
f"value for property '{name}' from '{value}'."
155-
) from e
155+
# NVD data error, monitor for fixed source data
156+
# and remove this fix
157+
if name == "configurations" and value == [{}]:
158+
value = [] # noqa: PLW2901
159+
logger.warning(
160+
"Empty node configuration for %s", data["id"]
161+
)
162+
else:
163+
raise ModelError(
164+
f"Error while creating {cls.__name__} model. Could not set " # pylint: disable=line-too-long # noqa: E501
165+
f"value for property '{name}' from '{value}'."
166+
) from e
156167

157168
if name in type_hints:
158169
kwargs[name] = value

tests/nvd/models/test_cve.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,19 @@ def test_configuration(self):
151151
self.assertIsNone(cpe_match.version_end_including)
152152
self.assertIsNone(cpe_match.version_end_excluding)
153153

154+
def test_configuration_node_empty_object(self):
155+
# Once this is fixed from NVD side, implement a test
156+
# that checks assertRaises(ModelError)
157+
cve = CVE.from_dict(
158+
get_cve_data(
159+
{
160+
"configurations": [{}],
161+
}
162+
)
163+
)
164+
165+
self.assertEqual(len(cve.configurations), 0)
166+
154167
def test_metrics_v2(self):
155168
cve = CVE.from_dict(
156169
get_cve_data(

0 commit comments

Comments
 (0)