Avoid use of json.Decoder
Per https://ahmetalpbalkan.com/blog/golang-json-decoder-pitfalls/
This commit is contained in:
parent
36210a9544
commit
9bf82346d8
|
@ -15,6 +15,7 @@ import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"os/user"
|
"os/user"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -119,14 +120,13 @@ func Main(argStateDir string, processCallback certspotter.ProcessCallback) int {
|
||||||
|
|
||||||
var logs []certspotter.LogInfo
|
var logs []certspotter.LogInfo
|
||||||
if *logsFilename != "" {
|
if *logsFilename != "" {
|
||||||
logFile, err := os.Open(*logsFilename)
|
logsJson, err := ioutil.ReadFile(*logsFilename)
|
||||||
if err != nil {
|
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
|
return 1
|
||||||
}
|
}
|
||||||
defer logFile.Close()
|
|
||||||
var logFileObj certspotter.LogInfoFile
|
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)
|
fmt.Fprintf(os.Stderr, "%s: Error decoding logs file: %s: %s\n", os.Args[0], *logsFilename, err)
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue