@@ -69,6 +69,16 @@ func (Detector) Requirements() *plugin.Capabilities {
69
69
// RequiredExtractors returns an empty list as there are no dependencies.
70
70
func (Detector ) RequiredExtractors () []string { return []string {} }
71
71
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
+
72
82
// Scan checks for the presence of the OpenSSH CVE-2023-38408 vulnerability on the filesystem.
73
83
func (d Detector ) Scan (ctx context.Context , scanRoot * scalibrfs.ScanRoot , ix * inventoryindex.InventoryIndex ) ([]* detector.Finding , error ) {
74
84
// 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
77
87
log .Debugf ("No OpenSSH version found" )
78
88
return nil , nil
79
89
}
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
+
81
96
if ! isVulnVersion {
82
97
log .Debugf ("Version %q not vuln" , openSSHVersion )
83
98
return nil , nil
@@ -232,15 +247,11 @@ type fileLocations struct {
232
247
LineNumbers []int
233
248
}
234
249
235
- func versionLessEqual (lower , upper string ) bool {
250
+ func versionLessEqual (lower , upper string ) ( bool , error ) {
236
251
// Version format looks like this: 3.7.1p2, 3.7, 3.2.3, 2.9p2
237
252
r , err := semantic .MustParse (lower , "Packagist" ).CompareStr (upper )
238
253
239
- if err != nil {
240
- panic (err )
241
- }
242
-
243
- return r <= 0
254
+ return r <= 0 , err
244
255
}
245
256
246
257
func findHistoryFiles () []string {
0 commit comments