Merge pull request #11182 from mvo5/crash-less-for-ondra

gadget: do not crash if gadget.yaml has an empty Volumes section
This commit is contained in:
Michael Vogt
2022-01-03 15:52:03 +01:00
committed by GitHub
2 changed files with 18 additions and 1 deletions

View File

@@ -462,7 +462,11 @@ func InfoFromGadgetYaml(gadgetYaml []byte, model Model) (*Info, error) {
// basic validation
var bootloadersFound int
knownFsLabelsPerVolume := make(map[string]map[string]bool, len(gi.Volumes))
for name, v := range gi.Volumes {
for name := range gi.Volumes {
v := gi.Volumes[name]
if v == nil {
return nil, fmt.Errorf("volume %q stanza is empty", name)
}
// set the VolumeName for the volume
v.Name = name
if err := validateVolume(v, knownFsLabelsPerVolume); err != nil {

View File

@@ -621,6 +621,19 @@ func (s *gadgetYamlTestSuite) TestCoreConfigDefaults(c *C) {
})
}
var mockGadgetWithEmptyVolumes = `device-tree-origin: kernel
volumes:
lun-0:
`
func (s *gadgetYamlTestSuite) TestRegressionGadgetWithEmptyVolume(c *C) {
err := ioutil.WriteFile(s.gadgetYamlPath, []byte(mockGadgetWithEmptyVolumes), 0644)
c.Assert(err, IsNil)
_, err = gadget.ReadInfo(s.dir, nil)
c.Assert(err, ErrorMatches, `volume "lun-0" stanza is empty`)
}
func (s *gadgetYamlTestSuite) TestReadGadgetDefaultsMultiline(c *C) {
err := ioutil.WriteFile(s.gadgetYamlPath, mockClassicGadgetMultilineDefaultsYaml, 0644)
c.Assert(err, IsNil)