From 5a87b2f5c8ccabfdf631cf9880a4ad18ec40191f Mon Sep 17 00:00:00 2001 From: zhouhao Date: Tue, 11 Oct 2016 17:49:15 +0800 Subject: [PATCH] add config validate Signed-off-by: zhouhao --- image/config.go | 12 +++++++++--- image/image.go | 4 ++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/image/config.go b/image/config.go index 0ae1344..fac7b31 100644 --- a/image/config.go +++ b/image/config.go @@ -15,6 +15,8 @@ package image import ( + "crypto/sha256" + "encoding/hex" "bytes" "encoding/json" "fmt" @@ -64,19 +66,23 @@ func findConfig(w walker, d *descriptor) (*config, error) { } } -func (c *config) validate(w walk) error { +func (c *config) validate(w walker) error { // check if the rootfs type is 'layers' if c.RootFS.Type != "layers" { - return errors.New("%q is an unknown rootfs type, MUST be 'layers'", c.RootFS.Type) + return errors.New("RootFs is an unknown rootfs type, MUST be 'layers'") } - for _, d = range c.RootFs.DiffIDs { + for _, d := range c.RootFS.DiffIDs { h := sha256.New() DiffIds := "sha256" + hex.EncodeToString(h.Sum(nil)) if DiffIds != d { return errors.New("DiffIDs mismatch") + } + } + + return nil } func (c *config) runtimeSpec(rootfs string) (*specs.Spec, error) { diff --git a/image/image.go b/image/image.go index 0bfc6a3..3377409 100644 --- a/image/image.go +++ b/image/image.go @@ -190,6 +190,10 @@ func createRuntimeBundle(w walker, dest, refName, rootfs string) error { return err } + if err := c.validate(w); err != nil { + return err + } + err = m.unpack(w, filepath.Join(dest, rootfs)) if err != nil { return err