From 5ae64d06043e785dc71607e031bdfb598854f8fd Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 7 Nov 2024 11:00:24 +0100 Subject: [PATCH] rhel: fix crash when PartitionType() is requested This commit fixes a crash in when the rhel ImageType.PartitionType() is called, here the BasePartitionTables function pointer is sometimes not initialized (e.g. in the `centos9/edge-commit` image type). --- pkg/distro/rhel/images_test.go | 5 +++++ pkg/distro/rhel/imagetype.go | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/pkg/distro/rhel/images_test.go b/pkg/distro/rhel/images_test.go index 21ec8c3844..c79197d878 100644 --- a/pkg/distro/rhel/images_test.go +++ b/pkg/distro/rhel/images_test.go @@ -438,3 +438,8 @@ func TestOsCustomizationsRHSM(t *testing.T) { }) } } + +func TestPartitionTypeNotCrashing(t *testing.T) { + it := &ImageType{} + assert.Equal(t, it.PartitionType(), "") +} diff --git a/pkg/distro/rhel/imagetype.go b/pkg/distro/rhel/imagetype.go index 35168f6d33..cbef71a7db 100644 --- a/pkg/distro/rhel/imagetype.go +++ b/pkg/distro/rhel/imagetype.go @@ -216,6 +216,10 @@ func (t *ImageType) getDefaultInstallerConfig() (*distro.InstallerConfig, error) } func (t *ImageType) PartitionType() string { + if t.BasePartitionTables == nil { + return "" + } + basePartitionTable, exists := t.BasePartitionTables(t) if !exists { return ""