cli/compose/types: UlimitsConfig.MarshalYAML() fix recursion

When marshaling the type with `gopkg.in/yaml.v3`, unmarshaling would
recursively call the type's `MarshalYAML()` function, which ultimately
resulted in a crash:

    runtime: goroutine stack exceeds 1000000000-byte limit
    runtime: sp=0x140202e0430 stack=[0x140202e0000, 0x140402e0000]
    fatal error: stack overflow

This applies a similar fix as was implemented in e7788d6f9a61d67566518efe11e394c414a21173
for the `MarshalJSON()` implementation. An alternative would be to use
a type alias (to remove the `MarshalYAML()`), but keeping it simple.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2022-11-16 21:38:32 +01:00
parent c18dd2719e
commit 0644aa3906
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C

View File

@ -441,7 +441,8 @@ func (u *UlimitsConfig) MarshalYAML() (interface{}, error) {
if u.Single != 0 { if u.Single != 0 {
return u.Single, nil return u.Single, nil
} }
return u, nil // Return as a value to avoid re-entering this method and use the default implementation
return *u, nil
} }
// MarshalJSON makes UlimitsConfig implement json.Marshaller // MarshalJSON makes UlimitsConfig implement json.Marshaller