Skip to content

Commit

Permalink
fix: make Alpine ecosystem fallback to latest release version (#1236)
Browse files Browse the repository at this point in the history
The latest release of osv.dev enforces the Alpine release version suffix
in queries.
Make the apk-installed parser use the latest Alpine version (`v3.20`)
when it can't find the version file to stop it from erroring.
  • Loading branch information
michaelkedar authored Sep 10, 2024
1 parent b402733 commit 981b0b5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
11 changes: 7 additions & 4 deletions pkg/lockfile/apk-installed.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
)

const AlpineEcosystem Ecosystem = "Alpine"
const AlpineFallbackVersion = "v3.20"

func groupApkPackageLines(scanner *bufio.Scanner) [][]string {
var groups [][]string
Expand Down Expand Up @@ -83,10 +84,12 @@ func (e ApkInstalledExtractor) Extract(f DepFile) ([]PackageDetails, error) {
}

alpineVersion, alpineVerErr := alpineReleaseExtractor(f)
if alpineVerErr == nil { // TODO: Log error? We might not be on a alpine system
for i := range packages {
packages[i].Ecosystem = Ecosystem(string(packages[i].Ecosystem) + ":" + alpineVersion)
}
if alpineVerErr != nil { // TODO: Log error? We might not be on a alpine system
// Alpine ecosystems MUST have a version suffix. Fallback to the latest version.
alpineVersion = AlpineFallbackVersion
}
for i := range packages {
packages[i].Ecosystem = Ecosystem(string(packages[i].Ecosystem) + ":" + alpineVersion)
}

if err := scanner.Err(); err != nil {
Expand Down
14 changes: 8 additions & 6 deletions pkg/lockfile/apk-installed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"github.com/google/osv-scanner/pkg/lockfile"
)

const alpineEcosystem = lockfile.AlpineEcosystem + ":" + lockfile.AlpineFallbackVersion

func TestParseApkInstalled_FileDoesNotExist(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -54,7 +56,7 @@ func TestParseApkInstalled_Malformed(t *testing.T) {
Name: "busybox",
Version: "",
Commit: "1dbf7a793afae640ea643a055b6dd4f430ac116b",
Ecosystem: lockfile.AlpineEcosystem,
Ecosystem: alpineEcosystem,
CompareAs: lockfile.AlpineEcosystem,
},
})
Expand All @@ -74,7 +76,7 @@ func TestParseApkInstalled_Single(t *testing.T) {
Name: "apk-tools",
Version: "2.12.10-r1",
Commit: "0188f510baadbae393472103427b9c1875117136",
Ecosystem: lockfile.AlpineEcosystem,
Ecosystem: alpineEcosystem,
CompareAs: lockfile.AlpineEcosystem,
},
})
Expand All @@ -94,7 +96,7 @@ func TestParseApkInstalled_Shuffled(t *testing.T) {
Name: "apk-tools",
Version: "2.12.10-r1",
Commit: "0188f510baadbae393472103427b9c1875117136",
Ecosystem: lockfile.AlpineEcosystem,
Ecosystem: alpineEcosystem,
CompareAs: lockfile.AlpineEcosystem,
},
})
Expand All @@ -114,21 +116,21 @@ func TestParseApkInstalled_Multiple(t *testing.T) {
Name: "alpine-baselayout-data",
Version: "3.4.0-r0",
Commit: "bd965a7ebf7fd8f07d7a0cc0d7375bf3e4eb9b24",
Ecosystem: lockfile.AlpineEcosystem,
Ecosystem: alpineEcosystem,
CompareAs: lockfile.AlpineEcosystem,
},
{
Name: "musl",
Version: "1.2.3-r4",
Commit: "f93af038c3de7146121c2ea8124ba5ce29b4b058",
Ecosystem: lockfile.AlpineEcosystem,
Ecosystem: alpineEcosystem,
CompareAs: lockfile.AlpineEcosystem,
},
{
Name: "busybox",
Version: "1.35.0-r29",
Commit: "1dbf7a793afae640ea643a055b6dd4f430ac116b",
Ecosystem: lockfile.AlpineEcosystem,
Ecosystem: alpineEcosystem,
CompareAs: lockfile.AlpineEcosystem,
},
})
Expand Down

0 comments on commit 981b0b5

Please sign in to comment.