From c283d9b5e89685c73ba856ea51e7d6d49b6922a9 Mon Sep 17 00:00:00 2001 From: Hsien-Tang Kao Date: Tue, 19 Feb 2019 00:48:19 -0800 Subject: [PATCH] signer/core: handle JSON unmarshal error (#19123) --- signer/core/abihelper.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/signer/core/abihelper.go b/signer/core/abihelper.go index de6b815a6..88c1da033 100644 --- a/signer/core/abihelper.go +++ b/signer/core/abihelper.go @@ -177,7 +177,9 @@ func NewAbiDBFromFile(path string) (*AbiDb, error) { if err != nil { return nil, err } - json.Unmarshal(raw, &db.db) + if err := json.Unmarshal(raw, &db.db); err != nil { + return nil, err + } return db, nil } @@ -192,14 +194,18 @@ func NewAbiDBFromFiles(standard, custom string) (*AbiDb, error) { if err != nil { return nil, err } - json.Unmarshal(raw, &db.db) + if err := json.Unmarshal(raw, &db.db); err != nil { + return nil, err + } // Custom file may not exist. Will be created during save, if needed if _, err := os.Stat(custom); err == nil { raw, err = ioutil.ReadFile(custom) if err != nil { return nil, err } - json.Unmarshal(raw, &db.customdb) + if err := json.Unmarshal(raw, &db.customdb); err != nil { + return nil, err + } } return db, nil