Skip to content

Commit 229ead6

Browse files
Merge pull request #2109 from mhanss/fix-rdh
OCPBUGS-62445: prevent crash when rootDeviceHints format is invalid
2 parents 6632635 + bd888e5 commit 229ead6

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
@@ -664,6 +664,13 @@ func TestCreateConfigFileFromFlags(t *testing.T) {
664664
},
665665
expectedConfigFile: expectedConfigFile,
666666
},
667+
{
668+
name: "root device hints incorrect",
669+
singleNodeCreateOptions: &singleNodeCreateOptions{
670+
RootDeviceHints: "/dev/sda",
671+
},
672+
expectedError: "incorrect rootDeviceHints format provided: /dev/sda. Expected format: <hint name>:<value>, for example: deviceName:/dev/sda",
673+
},
667674
{
668675
name: "ssh-key-path missing or incorrect",
669676
singleNodeCreateOptions: &singleNodeCreateOptions{

0 commit comments

Comments
 (0)