Skip to content

Commit

Permalink
Skip uninstalled dpkg packages (#5)
Browse files Browse the repository at this point in the history
When a package is uninstalled without --purge, the dpkg config is not removed from /var/lib/dpkg/status. The status is changed to deinstall. This has to be removed from SBOM.
  • Loading branch information
ramanan-ravi authored Nov 15, 2024
1 parent 659394c commit c75155e
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions syft/pkg/cataloger/debian/parse_dpkg_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func parseDpkgStatus(reader io.Reader) ([]pkg.DpkgDBEntry, error) {
// pkg.DpkgMetadata struct has different types for some fields (e.g. Provides, Depends, and PreDepends is []string, not a string).
type dpkgExtractedMetadata struct {
Package string `mapstructure:"Package"`
Status string `mapstructure:"Status"`
Source string `mapstructure:"Source"`
Version string `mapstructure:"Version"`
SourceVersion string `mapstructure:"SourceVersion"`
Expand Down Expand Up @@ -101,6 +102,11 @@ func parseDpkgStatusEntry(reader *bufio.Reader) (*pkg.DpkgDBEntry, error) {
return nil, err
}

if strings.Contains(raw.Status, "deinstall") {
log.Debugf("skipping package %s with status %s", raw.Package, raw.Status)
return nil, nil
}

sourceName, sourceVersion := extractSourceVersion(raw.Source)
if sourceVersion != "" {
raw.SourceVersion = sourceVersion
Expand Down

0 comments on commit c75155e

Please sign in to comment.