Skip to content

Commit 3f95e90

Browse files
committed
fix(plugins/config): add input string validation before JSON unmarshalling
1 parent 21e5250 commit 3f95e90

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

plugins/config/main.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,19 +122,23 @@ func (a *Asset) FromVar(name any, hostnames any, ipAddresses any, confidentialit
122122

123123
if hostnames != nil {
124124
hostnamesStr := utils.CastString(hostnames)
125-
err := json.Unmarshal([]byte(hostnamesStr), &hostnamesList)
126-
if err != nil {
127-
return catcher.Error("failed to unmarshal hostnames list", err, map[string]any{"process": "plugin_com.utmstack.config"})
125+
if hostnamesStr != "" {
126+
err := json.Unmarshal([]byte(hostnamesStr), &hostnamesList)
127+
if err != nil {
128+
return catcher.Error("failed to unmarshal hostnames list", err, map[string]any{"process": "plugin_com.utmstack.config"})
129+
}
128130
}
129131
}
130132

131133
var ipAddressesList []string
132134

133135
if ipAddresses != nil {
134136
ipAddressesStr := utils.CastString(ipAddresses)
135-
err := json.Unmarshal([]byte(ipAddressesStr), &ipAddressesList)
136-
if err != nil {
137-
return catcher.Error("failed to unmarshal ip addresses list", err, map[string]any{"process": "plugin_com.utmstack.config"})
137+
if ipAddressesStr != "" {
138+
err := json.Unmarshal([]byte(ipAddressesStr), &ipAddressesList)
139+
if err != nil {
140+
return catcher.Error("failed to unmarshal ip addresses list", err, map[string]any{"process": "plugin_com.utmstack.config"})
141+
}
138142
}
139143
}
140144

0 commit comments

Comments
 (0)