Commit fe1fdf8a authored by Adrian Sutton's avatar Adrian Sutton

op-node: Make JSON parsing for persisted state strict

parent 9d5c144d
package node package node
import ( import (
"bytes"
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
...@@ -113,9 +114,14 @@ func (p *ActiveConfigPersistence) read() (persistedState, error) { ...@@ -113,9 +114,14 @@ func (p *ActiveConfigPersistence) read() (persistedState, error) {
return persistedState{}, fmt.Errorf("read config file (%v): %w", p.file, err) return persistedState{}, fmt.Errorf("read config file (%v): %w", p.file, err)
} }
var config persistedState var config persistedState
if err = json.Unmarshal(data, &config); err != nil { dec := json.NewDecoder(bytes.NewReader(data))
dec.DisallowUnknownFields()
if err = dec.Decode(&config); err != nil {
return persistedState{}, fmt.Errorf("invalid config file (%v): %w", p.file, err) return persistedState{}, fmt.Errorf("invalid config file (%v): %w", p.file, err)
} }
if config.SequencerStarted == nil {
return persistedState{}, fmt.Errorf("missing sequencerStarted value in config file (%v)", p.file)
}
return config, nil return config, nil
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment