1
0
mirror of https://github.com/woodpecker-ci/woodpecker.git synced 2026-06-03 16:35:37 +02:00

fix: panic due to an invalid memory address when injectSecretRecursive encounters nil values (#5699)

This commit is contained in:
Harri Avellan
2025-10-31 09:10:00 +02:00
committed by GitHub
parent 068c49838d
commit 69fc5bfa25
2 changed files with 21 additions and 1 deletions
@@ -194,7 +194,9 @@ func injectSecret(v map[string]any, getSecretValue func(name string) (string, er
// it iterates recursively over them too, using injectSecret internally.
func injectSecretRecursive(v any, getSecretValue func(name string) (string, error)) (any, error) {
t := reflect.TypeOf(v)
if t == nil {
return v, nil
}
if !isComplex(t.Kind()) {
return v, nil
}
@@ -304,3 +304,21 @@ func TestSecretMappingComplexMapWithSecrets(t *testing.T) {
assert.Equal(t, expectedJSON, secretMapping["PLUGIN_CONFIG"])
assert.NotContains(t, secretMapping, "PLUGIN_SIMPLE_VAR")
}
func TestComplexTypesWithNilValuesWontPanic(t *testing.T) {
from := map[string]any{
"config": []any{
"copy a b",
map[string]any{
"foo": nil,
},
},
}
got := map[string]string{}
expectedJSON := `["copy a b",{"foo":null}]`
err := ParamsToEnv(from, got, "PLUGIN_", true, nil, nil)
assert.NoError(t, err)
assert.Equal(t, expectedJSON, got["PLUGIN_CONFIG"])
}