Skip to content

Commit

Permalink
Fix Vulnerabiliry Extension Deserialization Problem
Browse files Browse the repository at this point in the history
Signed-off-by: bors2908 <bors2908@gmail.com>
  • Loading branch information
boris-tomosystech authored and bors2908 committed Jun 27, 2023
1 parent 59c2790 commit 8011080
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions src/main/java/org/cyclonedx/util/ExtensionDeserializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,30 +210,46 @@ private List<Rating> processRatings(final JsonNode ratings) {
if (ratings != null) {
if (ratings.isArray() && !ratings.isEmpty()) {
for (JsonNode rating : ratings) {
ratingsList.add(processRating(rating));
ratingsList.addAll(processRatingIntermediate(rating));
}
} else {
ratingsList.add(processRating(ratings));
ratingsList.addAll(processRatingIntermediate(ratings));
}
}
return ratingsList.isEmpty() ? null : ratingsList;
}

private Rating processRating(final JsonNode ratingNode) {
Rating rating = new Rating();
private List<Rating> processRatingIntermediate(final JsonNode ratingNode) {
List<Rating> ratingsList = new ArrayList<>();

JsonNode r = ratingNode.get(Vulnerability10.RATING);

if (r != null) {
if (r.get(Vulnerability10.SCORE) != null) {
if (r.isArray() && !r.isEmpty()) {
for (JsonNode rating : r) {
ratingsList.add(processRating(rating));
}
} else {
ratingsList.add(processRating(r));
}
}
return ratingsList;
}

private Rating processRating(final JsonNode ratingNode) {
Rating rating = new Rating();
if (ratingNode != null) {
if (ratingNode.get(Vulnerability10.SCORE) != null) {
Score score = new Score();
JsonNode s = r.get(Vulnerability10.SCORE);
JsonNode s = ratingNode.get(Vulnerability10.SCORE);
score.setBase(getAsDouble(Vulnerability10.BASE, s));
score.setImpact(getAsDouble(Vulnerability10.IMPACT, s));
score.setExploitability(getAsDouble(Vulnerability10.EXPLOITABILITY, s));
rating.setScore(score);
}
rating.setSeverity(Severity.fromString(getAsString(Vulnerability10.SEVERITY, r)));
rating.setMethod(ScoreSource.fromString(getAsString(Vulnerability10.METHOD, r)));
rating.setVector(getAsString(Vulnerability10.VECTOR, r));
rating.setSeverity(Severity.fromString(getAsString(Vulnerability10.SEVERITY, ratingNode)));
rating.setMethod(ScoreSource.fromString(getAsString(Vulnerability10.METHOD, ratingNode)));
rating.setVector(getAsString(Vulnerability10.VECTOR, ratingNode));
}

return rating;
Expand Down

0 comments on commit 8011080

Please sign in to comment.