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

Align GoVulncheck Go version with go.mod #818

Merged
merged 6 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 9 additions & 0 deletions internal/sourceanalysis/go.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ func goAnalysis(r reporter.Reporter, pkgs []models.PackageVulns, source models.S
return
}

// Set GOVERSION to the Go version in go.mod.
var goVersion string
for _, pkg := range pkgs {
if pkg.Package.Name == "stdlib" {
goVersion = pkg.Package.Version
}
}
os.Setenv("GOVERSION", fmt.Sprintf("go%s", goVersion))

vulns, vulnsByID := vulnsFromAllPkgs(pkgs)
res, err := runGovulncheck(filepath.Dir(source.Path), vulns)
if err != nil {
Expand Down
9 changes: 5 additions & 4 deletions pkg/osvscanner/osvscanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ func DoScan(actions ScannerActions, r reporter.Reporter) (models.VulnerabilityRe
r.Infof("Filtered %d local package/s from the scan.\n", len(scannedPackages)-len(filteredScannedPackages))
}

vulnsResp, err := makeRequest(r, filteredScannedPackages, actions.CompareLocally, actions.CompareOffline, actions.LocalDBPath)
vulnsResp, err := makeRequest(r, &filteredScannedPackages, actions.CompareLocally, actions.CompareOffline, actions.LocalDBPath)
if err != nil {
return models.VulnerabilityResults{}, err
}
Expand Down Expand Up @@ -862,7 +862,7 @@ func filterUnscannablePackages(packages []scannedPackage) []scannedPackage {

// patchPackageForRequest modifies packages before they are sent to osv.dev to
// account for edge cases.
func patchPackageForRequest(pkg scannedPackage) scannedPackage {
func patchPackageForRequest(pkg *scannedPackage) *scannedPackage {
// Assume Go stdlib patch version as the latest version
//
// This is done because go1.20 and earlier do not support patch
Expand All @@ -888,13 +888,14 @@ func patchPackageForRequest(pkg scannedPackage) scannedPackage {

func makeRequest(
r reporter.Reporter,
packages []scannedPackage,
packages *[]scannedPackage,
compareLocally bool,
compareOffline bool,
localDBPath string) (*osv.HydratedBatchedResponse, error) {
// Make OSV queries from the packages.
var query osv.BatchedQuery
for _, p := range packages {
for i := range *packages {
p := &(*packages)[i]
p = patchPackageForRequest(p)
switch {
// Prefer making package requests where possible.
Expand Down
Loading