Skip to content

Commit

Permalink
dpkg: fix path handling
Browse files Browse the repository at this point in the history
This fixes a bug reported via #381 where paths weren't normalized the
same way after reading the names from the tar header.

This backports #402.

Signed-off-by: Hank Donnay <[email protected]>
  • Loading branch information
hdonnay committed Jun 9, 2021
1 parent c809930 commit 11837c4
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
3 changes: 2 additions & 1 deletion dpkg/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ Find:
var db io.Reader
var h *tar.Header
for h, err = tr.Next(); err == nil; h, err = tr.Next() {
if h.Name == fn {
// The location from above is cleaned, so make sure to do that.
if c := filepath.Clean(h.Name); c == fn {
db = tr
break
}
Expand Down
33 changes: 33 additions & 0 deletions dpkg/scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,39 @@ func TestScanner(t *testing.T) {
}
}

func TestAbsolutePaths(t *testing.T) {
ctx := zlog.Test(context.Background(), t)
hash, err := claircore.ParseDigest("sha256:3c9020349340788076971d5ea638b71e35233fd8e149e269d8eebfa17960c03f")
if err != nil {
t.Fatal(err)
}
l := &claircore.Layer{
Hash: hash,
}

tctx, done := context.WithTimeout(ctx, 30*time.Second)
defer done()
n, err := fetch.Layer(tctx, t, http.DefaultClient, "gcr.io", "vmwarecloudadvocacy/acmeshop-user", hash)
if err != nil {
t.Error(err)
}
defer n.Close()

if err := l.SetLocal(n.Name()); err != nil {
t.Error(err)
}

s := &Scanner{}
got, err := s.Scan(ctx, l)
if err != nil {
t.Fatal(err)
}
t.Logf("found %d packages", len(got))
if len(got) == 0 {
t.Fail()
}
}

func TestExtraMetadata(t *testing.T) {
const layerfile = `testdata/extrametadata.layer`
l := claircore.Layer{
Expand Down
1 change: 1 addition & 0 deletions test/fetch/layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const (
var registry = map[string]*client{
"docker.io": &client{Root: "https://registry-1.docker.io/"},
"quay.io": &client{Root: "https://quay.io/"},
"gcr.io": &client{Root: "https://gcr.io/"},
}

func Layer(ctx context.Context, t *testing.T, c *http.Client, from, repo string, blob claircore.Digest) (*os.File, error) {
Expand Down

0 comments on commit 11837c4

Please sign in to comment.