Skip to content

Commit

Permalink
fix: skip filling in empty fields in APK metadata (anchore#1484)
Browse files Browse the repository at this point in the history
Signed-off-by: Nils Hanke <[email protected]>

Signed-off-by: Nils Hanke <[email protected]>
  • Loading branch information
Nirusu authored Jan 20, 2023
1 parent 13e355c commit fa826ad
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 0 deletions.
8 changes: 8 additions & 0 deletions syft/pkg/cataloger/apkdb/parse_apk_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ func parseApkDB(_ source.FileResolver, env *generic.Environment, reader source.L
log.Warnf("unable to parse field data from line %q", line)
continue
}
if len(field.name) == 0 {
log.Warnf("failed to parse field name from line %q", line)
continue
}
if len(field.value) == 0 {
log.Debugf("line %q: parsed field %q appears to have an empty value, skipping", line, field.name)
continue
}

entryParsingInProgress = true

Expand Down
37 changes: 37 additions & 0 deletions syft/pkg/cataloger/apkdb/parse_apk_db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,43 @@ func TestSinglePackageDetails(t *testing.T) {
},
},
},
{
fixture: "test-fixtures/empty-deps-and-provides",
expected: pkg.ApkMetadata{
Package: "alpine-baselayout-data",
OriginPackage: "alpine-baselayout",
Version: "3.4.0-r0",
Description: "Alpine base dir structure and init scripts",
Maintainer: "Natanael Copa <[email protected]>",
License: "GPL-2.0-only",
Architecture: "x86_64",
URL: "https://git.alpinelinux.org/cgit/aports/tree/main/alpine-baselayout",
Size: 11664,
InstalledSize: 77824,
Dependencies: []string{},
Provides: []string{},
Checksum: "Q15ffjKT28lB7iSXjzpI/eDdYRCwM=",
GitCommit: "bd965a7ebf7fd8f07d7a0cc0d7375bf3e4eb9b24",
Files: []pkg.ApkFileRecord{
{Path: "/etc"},
{Path: "/etc/fstab"},
{Path: "/etc/group"},
{Path: "/etc/hostname"},
{Path: "/etc/hosts"},
{Path: "/etc/inittab"},
{Path: "/etc/modules"},
{Path: "/etc/mtab", OwnerUID: "0", OwnerGID: "0", Permissions: "0777"},
{Path: "/etc/nsswitch.conf"},
{Path: "/etc/passwd"},
{Path: "/etc/profile"},
{Path: "/etc/protocols"},
{Path: "/etc/services"},
{Path: "/etc/shadow", OwnerUID: "0", OwnerGID: "148", Permissions: "0640"},
{Path: "/etc/shells"},
{Path: "/etc/sysctl.conf"},
},
},
},
{
fixture: "test-fixtures/base",
expected: pkg.ApkMetadata{
Expand Down
35 changes: 35 additions & 0 deletions syft/pkg/cataloger/apkdb/test-fixtures/empty-deps-and-provides
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
P:alpine-baselayout-data
V:3.4.0-r0
A:x86_64
L:GPL-2.0-only
T:Alpine base dir structure and init scripts
o:alpine-baselayout
m:Natanael Copa <[email protected]>
U:https://git.alpinelinux.org/cgit/aports/tree/main/alpine-baselayout
D:
p:
c:bd965a7ebf7fd8f07d7a0cc0d7375bf3e4eb9b24
i:[]
t:1667573027
S:11664
I:77824
k:0
C:Q15ffjKT28lB7iSXjzpI/eDdYRCwM=
F:etc
R:fstab
R:group
R:hostname
R:hosts
R:inittab
R:modules
R:mtab
a:0:0:0777
R:nsswitch.conf
R:passwd
R:profile
R:protocols
R:services
R:shadow
a:0:148:0640
R:shells
R:sysctl.conf

0 comments on commit fa826ad

Please sign in to comment.