Skip to content

Commit 35588ba

Browse files
committed
fix: don't panic if openSSH version cannot be parsed
1 parent b4b7d56 commit 35588ba

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

detector/cve/cve202338408/cve202338408.go

+18-7
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ func (Detector) Requirements() *plugin.Capabilities {
6969
// RequiredExtractors returns an empty list as there are no dependencies.
7070
func (Detector) RequiredExtractors() []string { return []string{} }
7171

72+
func isVersionWithinRange(openSSHVersion string, lower string, upper string) (bool, error) {
73+
isWithinRange, err := versionLessEqual(lower, openSSHVersion)
74+
75+
if !isWithinRange || err != nil {
76+
return false, err
77+
}
78+
79+
return versionLessEqual(openSSHVersion, upper)
80+
}
81+
7282
// Scan checks for the presence of the OpenSSH CVE-2023-38408 vulnerability on the filesystem.
7383
func (d Detector) Scan(ctx context.Context, scanRoot *scalibrfs.ScanRoot, ix *inventoryindex.InventoryIndex) ([]*detector.Finding, error) {
7484
// 1. OpenSSH between and 5.5 and 9.3p1 (inclusive)
@@ -77,7 +87,12 @@ func (d Detector) Scan(ctx context.Context, scanRoot *scalibrfs.ScanRoot, ix *in
7787
log.Debugf("No OpenSSH version found")
7888
return nil, nil
7989
}
80-
isVulnVersion := versionLessEqual("5.5", openSSHVersion) && versionLessEqual(openSSHVersion, "9.3p1")
90+
isVulnVersion, err := isVersionWithinRange(openSSHVersion, "5.5", "9.3p1")
91+
92+
if err != nil {
93+
return nil, err
94+
}
95+
8196
if !isVulnVersion {
8297
log.Debugf("Version %q not vuln", openSSHVersion)
8398
return nil, nil
@@ -232,15 +247,11 @@ type fileLocations struct {
232247
LineNumbers []int
233248
}
234249

235-
func versionLessEqual(lower, upper string) bool {
250+
func versionLessEqual(lower, upper string) (bool, error) {
236251
// Version format looks like this: 3.7.1p2, 3.7, 3.2.3, 2.9p2
237252
r, err := semantic.MustParse(lower, "Packagist").CompareStr(upper)
238253

239-
if err != nil {
240-
panic(err)
241-
}
242-
243-
return r <= 0
254+
return r <= 0, err
244255
}
245256

246257
func findHistoryFiles() []string {

0 commit comments

Comments
 (0)