From 2796b3521ad37c7fd29837ec11e5ee22dfdcef1f Mon Sep 17 00:00:00 2001 From: Bhavishya Jain <65864699+bhavishyajain545@users.noreply.github.com> Date: Sat, 21 Nov 2026 19:15:02 +0530 Subject: [PATCH] fix(alluxio): avoid index out of range in MasterPodName MasterPodName read str[1] after checking len(str) < 1 and data[2] after checking len(data) < 2, so output of alluxio fsadmin report without the master address on its second line caused a panic instead of the intended error. Check for the lengths that are actually indexed. Signed-off-by: Bhavishya Jain <65864699+bhavishyajain545@users.noreply.github.com> --- pkg/ddc/alluxio/operations/base.go | 4 ++-- pkg/ddc/alluxio/operations/base_test.go | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/pkg/ddc/alluxio/operations/base.go b/pkg/ddc/alluxio/operations/base.go index d745cfd6e6e..8b3ff2ebe56 100644 --- a/pkg/ddc/alluxio/operations/base.go +++ b/pkg/ddc/alluxio/operations/base.go @@ -479,13 +479,13 @@ func (a AlluxioFileUtils) MasterPodName() (masterPodName string, err error) { redactedCommand := securityutils.FilterCommand(command) str := strings.Split(stdout, "\n") - if len(str) < 1 { + if len(str) < 2 { message := fmt.Sprintf("get wrong result when using command %v", redactedCommand) return a.podName, errors.New(message) } data := strings.Fields(str[1]) - if len(data) < 2 { + if len(data) < 3 { message := fmt.Sprintf("get wrong result when using command %v", redactedCommand) return a.podName, errors.New(message) } diff --git a/pkg/ddc/alluxio/operations/base_test.go b/pkg/ddc/alluxio/operations/base_test.go index 09e1f752772..84be72aa6fb 100644 --- a/pkg/ddc/alluxio/operations/base_test.go +++ b/pkg/ddc/alluxio/operations/base_test.go @@ -797,6 +797,22 @@ func TestAlluxioFileUtils_MasterPodName(t *testing.T) { if address != "192.168.0.193" { t.Errorf("check failure, want: %s, got: %s", "192.168.0.193", address) } + + // Output that does not have the master address on the second line must return an error, not panic. + for _, stdout := range []string{ + "", + "Alluxio cluster summary: ", + "Alluxio cluster summary: \n", + "Alluxio cluster summary: \n Master Address:", + } { + ExecUnexpected := func(a AlluxioFileUtils, command []string, verbose bool) (string, string, error) { + return stdout, "", nil + } + patches.ApplyPrivateMethod(reflect.TypeOf(AlluxioFileUtils{}), "exec", ExecUnexpected) + if _, err := a.MasterPodName(); err == nil { + t.Errorf("check failure for stdout %q, want err, got nil", stdout) + } + } } func TestAlluxioFileUtils_ExecMountScripts(t *testing.T) {