Skip to content

Commit bd888e5

Browse files
committed
fix(node-image): prevent crash when rootDeviceHints format is invalid
1 parent a43ea28 commit bd888e5

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

pkg/cli/admin/nodeimage/create.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,9 @@ func (o *CreateOptions) createConfigFileFromFlags() ([]byte, error) {
635635
}
636636
if o.SingleNodeOpts.RootDeviceHints != "" {
637637
parts := strings.SplitN(o.SingleNodeOpts.RootDeviceHints, ":", 2)
638+
if len(parts) != 2 {
639+
return nil, fmt.Errorf("incorrect rootDeviceHints format provided: %s. Expected format: <hint name>:<value>, for example: deviceName:/dev/sda", o.SingleNodeOpts.RootDeviceHints)
640+
}
638641
host["rootDeviceHints"] = map[string]interface{}{
639642
parts[0]: parts[1],
640643
}

pkg/cli/admin/nodeimage/create_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,13 @@ func TestCreateConfigFileFromFlags(t *testing.T) {
662662
},
663663
expectedConfigFile: expectedConfigFile,
664664
},
665+
{
666+
name: "root device hints incorrect",
667+
singleNodeCreateOptions: &singleNodeCreateOptions{
668+
RootDeviceHints: "/dev/sda",
669+
},
670+
expectedError: "incorrect rootDeviceHints format provided: /dev/sda. Expected format: <hint name>:<value>, for example: deviceName:/dev/sda",
671+
},
665672
{
666673
name: "ssh-key-path missing or incorrect",
667674
singleNodeCreateOptions: &singleNodeCreateOptions{

0 commit comments

Comments
 (0)