Use strict JSON decoding

This commit is contained in:
Holger Obermaier
2026-03-10 15:24:00 +01:00
parent 7a897e8d3f
commit a5264ffba7

View File

@@ -1,6 +1,7 @@
package collectors
import (
"bytes"
"encoding/json"
"fmt"
"os/exec"
@@ -129,7 +130,9 @@ func (m *SmartMonCollector) Init(config json.RawMessage) error {
// Read in the JSON configuration
if len(config) > 0 {
if err := json.Unmarshal(config, &m.config); err != nil {
d := json.NewDecoder(bytes.NewReader(config))
d.DisallowUnknownFields()
if err := d.Decode(&m.config); err != nil {
return fmt.Errorf("%s Init(): Error reading config: %w", m.name, err)
}
}