Skip to content

Commit

Permalink
ubuntu: verify dist is actually ubuntu
Browse files Browse the repository at this point in the history
Signed-off-by: RTann <[email protected]>
  • Loading branch information
RTann committed Jun 22, 2023
1 parent 821f255 commit 14a482d
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 207 deletions.
11 changes: 9 additions & 2 deletions ubuntu/distributionscanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

const (
scannerName = "ubuntu"
scannerVersion = "2"
scannerVersion = "3"
scannerKind = "distribution"

osReleasePath = `etc/os-release`
Expand Down Expand Up @@ -74,16 +74,18 @@ func (ds *DistributionScanner) Scan(ctx context.Context, l *claircore.Layer) ([]
func findDist(sys fs.FS) (*claircore.Distribution, error) {
var err error
var b []byte
var verKey, nameKey string
var idKey, verKey, nameKey string

b, err = fs.ReadFile(sys, lsbReleasePath)
if errors.Is(err, nil) {
idKey = `DISTRIB_ID`
verKey = `DISTRIB_RELEASE`
nameKey = `DISTRIB_CODENAME`
goto Found
}
b, err = fs.ReadFile(sys, osReleasePath)
if errors.Is(err, nil) {
idKey = `ID`
verKey = `VERSION_ID`
nameKey = `VERSION_CODENAME`
goto Found
Expand All @@ -106,6 +108,11 @@ Found:
}
v = strings.Trim(v, "\"\r\n")
switch k {
case idKey:
if !strings.EqualFold(v, "ubuntu") {
// This is not Ubuntu, so skip it.
return nil, nil
}
case nameKey:
name = v
case verKey:
Expand Down
Loading

0 comments on commit 14a482d

Please sign in to comment.