Merge pull request #317 from crawford/json

configdrive: check metadata length before parsing
This commit is contained in:
Alex Crawford 2015-02-13 10:22:57 -08:00
commit 19ce7ac849
2 changed files with 5 additions and 1 deletions

View File

@ -60,7 +60,7 @@ func (cd *configDrive) FetchMetadata() (metadata datasource.Metadata, err error)
} `json:"network_config"`
}
if data, err = cd.tryReadFile(path.Join(cd.openstackVersionRoot(), "meta_data.json")); err != nil {
if data, err = cd.tryReadFile(path.Join(cd.openstackVersionRoot(), "meta_data.json")); err != nil || len(data) == 0 {
return
}
if err = json.Unmarshal([]byte(data), &m); err != nil {

View File

@ -29,6 +29,10 @@ func TestFetchMetadata(t *testing.T) {
metadata datasource.Metadata
}{
{
root: "/",
files: test.MockFilesystem{"/openstack/latest/meta_data.json": ""},
},
{
root: "/",
files: test.MockFilesystem{"/openstack/latest/meta_data.json": `{"ignore": "me"}`},