From 9bf82346d8df8e336e0f2acd78ea332e6590c930 Mon Sep 17 00:00:00 2001 From: Andrew Ayer Date: Tue, 15 Nov 2016 12:43:31 -0800 Subject: [PATCH] Avoid use of json.Decoder Per https://ahmetalpbalkan.com/blog/golang-json-decoder-pitfalls/ --- cmd/common.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cmd/common.go b/cmd/common.go index b1c9c97..4491da4 100644 --- a/cmd/common.go +++ b/cmd/common.go @@ -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 }