From b47711ae92619f04e070b284f47e203c79640d9e Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Wed, 10 Aug 2016 16:48:17 -0700 Subject: [PATCH] check plugin manifest is correctly formatted before push Signed-off-by: Victor Vieux --- plugin/backend.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/plugin/backend.go b/plugin/backend.go index 72198b27e2..b8a35979e3 100644 --- a/plugin/backend.go +++ b/plugin/backend.go @@ -3,7 +3,10 @@ package plugin import ( + "bytes" + "encoding/json" "fmt" + "io/ioutil" "net/http" "os" "path/filepath" @@ -114,11 +117,16 @@ func (pm *Manager) Push(name string, metaHeader http.Header, authConfig *types.A return err } dest := filepath.Join(pm.libRoot, p.PluginObj.ID) - config, err := os.Open(filepath.Join(dest, "manifest.json")) + config, err := ioutil.ReadFile(filepath.Join(dest, "manifest.json")) + if err != nil { + return err + } + + var dummy types.Plugin + err = json.Unmarshal(config, &dummy) if err != nil { return err } - defer config.Close() rootfs, err := archive.Tar(filepath.Join(dest, "rootfs"), archive.Gzip) if err != nil { @@ -126,7 +134,7 @@ func (pm *Manager) Push(name string, metaHeader http.Header, authConfig *types.A } defer rootfs.Close() - _, err = distribution.Push(name, pm.registryService, metaHeader, authConfig, config, rootfs) + _, err = distribution.Push(name, pm.registryService, metaHeader, authConfig, ioutil.NopCloser(bytes.NewReader(config)), rootfs) // XXX: Ignore returning digest for now. // Since digest needs to be written to the ProgressWriter. return err