-
Notifications
You must be signed in to change notification settings - Fork 90
#1628: Support for OS specific CVEs #2370
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
832df30
b64ebf5
aee1143
4765aff
e926035
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,9 +3,12 @@ | |||||||||||||
| import java.util.ArrayList; | ||||||||||||||
| import java.util.Iterator; | ||||||||||||||
| import java.util.List; | ||||||||||||||
| import java.util.Map; | ||||||||||||||
| import java.util.Objects; | ||||||||||||||
| import java.util.TreeMap; | ||||||||||||||
|
|
||||||||||||||
| import com.devonfw.tools.ide.json.JsonObject; | ||||||||||||||
| import com.devonfw.tools.ide.os.OperatingSystem; | ||||||||||||||
| import com.devonfw.tools.ide.version.VersionIdentifier; | ||||||||||||||
| import com.devonfw.tools.ide.version.VersionRange; | ||||||||||||||
| import com.devonfw.tools.ide.version.VersionRangeRelation; | ||||||||||||||
|
|
@@ -17,20 +20,62 @@ | |||||||||||||
| * @param severity the severity in the range from (0,10.0] where 10.0 is most critical. | ||||||||||||||
| * @param versions the {@link VersionRange}s of the affected versions. Typically one entry but might also affect multiple ranges. E.g. "[1.0,1.2)" and | ||||||||||||||
| * "[2.0,2.2)". Should never be {@code null} or {@link List#isEmpty() empty}. | ||||||||||||||
| * @param conditions the additional {@link VersionRange}s of affected versions per {@link OperatingSystem#toString() operating system}. Only relevant when the | ||||||||||||||
| * end-user runs IDEasy on the matching operating system. Never {@code null} but may be {@link Map#isEmpty() empty}. | ||||||||||||||
| * @see ToolSecurity | ||||||||||||||
| */ | ||||||||||||||
| public record Cve(String id, double severity, List<VersionRange> versions) implements JsonObject { | ||||||||||||||
| public record Cve(String id, double severity, List<VersionRange> versions, Map<String, List<VersionRange>> conditions) implements JsonObject { | ||||||||||||||
|
|
||||||||||||||
| static final String PROPERTY_ID = "id"; | ||||||||||||||
|
|
||||||||||||||
| static final String PROPERTY_SEVERITY = "severity"; | ||||||||||||||
|
|
||||||||||||||
| static final String PROPERTY_VERSIONS = "versions"; | ||||||||||||||
|
|
||||||||||||||
| static final String PROPERTY_CONDITIONS = "conditions"; | ||||||||||||||
|
|
||||||||||||||
| public Cve { | ||||||||||||||
| Objects.requireNonNull(id); | ||||||||||||||
| Objects.requireNonNull(versions); | ||||||||||||||
| assert !versions.isEmpty(); | ||||||||||||||
| if (conditions == null) { | ||||||||||||||
| conditions = Map.of(); | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| /** | ||||||||||||||
| * @param id the {@link #id()}. | ||||||||||||||
| * @param severity the {@link #severity()}. | ||||||||||||||
| * @param versions the {@link #versions()}. | ||||||||||||||
| */ | ||||||||||||||
| public Cve(String id, double severity, List<VersionRange> versions) { | ||||||||||||||
|
|
||||||||||||||
| this(id, severity, versions, Map.of()); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| /** | ||||||||||||||
| * @param version the {@link VersionIdentifier} to check. | ||||||||||||||
| * @param os the current {@link OperatingSystem} (may be {@code null}). | ||||||||||||||
| * @return {@code true} if the given {@link VersionIdentifier} is affected by this CVE on the given {@link OperatingSystem}, {@code false} otherwise. | ||||||||||||||
| */ | ||||||||||||||
| public boolean isAffected(VersionIdentifier version, OperatingSystem os) { | ||||||||||||||
|
|
||||||||||||||
| if (contains(this.versions, version)) { | ||||||||||||||
| return true; | ||||||||||||||
| } | ||||||||||||||
| return (os != null) && contains(this.conditions.get(os.toString()), version); | ||||||||||||||
|
laert-ll marked this conversation as resolved.
|
||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| private static boolean contains(List<VersionRange> ranges, VersionIdentifier version) { | ||||||||||||||
|
|
||||||||||||||
| if (ranges != null) { | ||||||||||||||
| for (VersionRange range : ranges) { | ||||||||||||||
| if (range.contains(version)) { | ||||||||||||||
| return true; | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
| return false; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| /** | ||||||||||||||
|
|
@@ -49,7 +94,21 @@ public Cve merge(Cve issue) { | |||||||||||||
| for (VersionRange versionRange : issue.versions) { | ||||||||||||||
| mergeVersionRage(newVersions, versionRange); | ||||||||||||||
| } | ||||||||||||||
| return new Cve(this.id, this.severity, newVersions); | ||||||||||||||
| return new Cve(this.id, this.severity, newVersions, mergeConditions(issue.conditions)); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| private Map<String, List<VersionRange>> mergeConditions(Map<String, List<VersionRange>> other) { | ||||||||||||||
|
|
||||||||||||||
| if (this.conditions.isEmpty() && other.isEmpty()) { | ||||||||||||||
| return Map.of(); | ||||||||||||||
| } | ||||||||||||||
|
Comment on lines
+102
to
+104
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't this make more sense here?
Suggested change
|
||||||||||||||
| Map<String, List<VersionRange>> newConditions = new TreeMap<>(); | ||||||||||||||
| this.conditions.forEach((os, ranges) -> newConditions.put(os, new ArrayList<>(ranges))); | ||||||||||||||
|
Comment on lines
+105
to
+106
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can be simplified and made more efficient:
Suggested change
|
||||||||||||||
| other.forEach((os, ranges) -> { | ||||||||||||||
| List<VersionRange> newRanges = newConditions.computeIfAbsent(os, key -> new ArrayList<>()); | ||||||||||||||
| ranges.forEach(range -> mergeVersionRage(newRanges, range)); | ||||||||||||||
| }); | ||||||||||||||
| return newConditions; | ||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This
Suggested change
|
||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| /** | ||||||||||||||
|
|
||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.