Skip to content
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

fix: don't panic if openSSH version cannot be parsed #514

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions detector/cve/cve202338408/cve202338408.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package cve202338408
import (
"bufio"
"context"
"errors"
"fmt"
"os"
"os/exec"
Expand Down Expand Up @@ -69,6 +70,13 @@ func (Detector) Requirements() *plugin.Capabilities {
// RequiredExtractors returns an empty list as there are no dependencies.
func (Detector) RequiredExtractors() []string { return []string{} }

func isVersionWithinRange(openSSHVersion string, lower string, upper string) (bool, error) {
lessEq, err1 := versionLessEqual(lower, openSSHVersion)
greaterEq, err2 := versionLessEqual(openSSHVersion, upper)

return lessEq && greaterEq, errors.Join(err1, err2)
}

// Scan checks for the presence of the OpenSSH CVE-2023-38408 vulnerability on the filesystem.
func (d Detector) Scan(ctx context.Context, scanRoot *scalibrfs.ScanRoot, ix *inventoryindex.InventoryIndex) ([]*detector.Finding, error) {
// 1. OpenSSH between and 5.5 and 9.3p1 (inclusive)
Expand All @@ -77,7 +85,12 @@ func (d Detector) Scan(ctx context.Context, scanRoot *scalibrfs.ScanRoot, ix *in
log.Debugf("No OpenSSH version found")
return nil, nil
}
isVulnVersion := versionLessEqual("5.5", openSSHVersion) && versionLessEqual(openSSHVersion, "9.3p1")
isVulnVersion, err := isVersionWithinRange(openSSHVersion, "5.5", "9.3p1")

if err != nil {
return nil, err
}

if !isVulnVersion {
log.Debugf("Version %q not vuln", openSSHVersion)
return nil, nil
Expand Down Expand Up @@ -232,15 +245,11 @@ type fileLocations struct {
LineNumbers []int
}

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

if err != nil {
panic(err)
}

return r <= 0
return r <= 0, err
}

func findHistoryFiles() []string {
Expand Down
Loading