Avoid use of json.Decoder

Per https://ahmetalpbalkan.com/blog/golang-json-decoder-pitfalls/
This commit is contained in:
Andrew Ayer 2016-11-15 12:43:31 -08:00
parent 36210a9544
commit 9bf82346d8
1 changed files with 4 additions and 4 deletions

View File

@ -15,6 +15,7 @@ import (
"flag"
"fmt"
"log"
"io/ioutil"
"os"
"os/user"
"path/filepath"
@ -119,14 +120,13 @@ func Main(argStateDir string, processCallback certspotter.ProcessCallback) int {
var logs []certspotter.LogInfo
if *logsFilename != "" {
logFile, err := os.Open(*logsFilename)
logsJson, err := ioutil.ReadFile(*logsFilename)
if err != nil {
fmt.Fprintf(os.Stderr, "%s: Error opening logs file for reading: %s: %s\n", os.Args[0], *logsFilename, err)
fmt.Fprintf(os.Stderr, "%s: Error reading logs file: %s: %s\n", os.Args[0], *logsFilename, err)
return 1
}
defer logFile.Close()
var logFileObj certspotter.LogInfoFile
if err := json.NewDecoder(logFile).Decode(&logFileObj); err != nil {
if err := json.Unmarshal(logsJson, &logFileObj); err != nil {
fmt.Fprintf(os.Stderr, "%s: Error decoding logs file: %s: %s\n", os.Args[0], *logsFilename, err)
return 1
}