We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Noticed via an audit, the code from (*StandardLogWriter).PrintLogs() requests for *os.File but never closes it
cosmos-sdk/x/simulation/log.go
Lines 36 to 47 in 13b5a8d
We should be checking that the error returned after os.Create(filepath) checks an error and panics if non-nil
Lines 61 to 64 in 13b5a8d
We need to fix that code in the 2 places as
// PrintLogs - print the logs to a simulation file func (lw *StandardLogWriter) PrintLogs() { f := createLogFile() defer f.Close() for i := 0; i < len(lw.OpEntries); i++ { writeEntry := fmt.Sprintf("%s\n", (lw.OpEntries[i]).MustMarshal()) _, err := f.WriteString(writeEntry) if err != nil { panic("Failed to write logs to file") } } } func createLogFile() *os.File { fileName := fmt.Sprintf("%s.log", time.Now().Format("2006-01-02_15:04:05")) folderPath := os.ExpandEnv("$HOME/.simapp/simulations") filePath := path.Join(folderPath, fileName) if err := os.MkdirAll(folderPath, os.ModePerm); err != nil { panic(err) } f, err := os.Create(filePath) if err != nil { panic(err) } fmt.Printf("Logs to writing to %s\n", filePath) return f }
The text was updated successfully, but these errors were encountered:
Even better, perhaps we need to remove that harded "/" separators to make it
folderPath := filepath.Join(os.ExpandEnv("$HOME"), ".simapp", "simulations")
Sorry, something went wrong.
simulation: close opened files and check for error while creating files
b34f58c
From: #8217 Closes: #6784 Thanks: @PrathyushaLakkireddy for the original patch. Co-authored-by: Alessio Treglia <alessio@tendermint.com> Co-authored-by: Anil Kumar Kammari <anil@vitwit.com>
simulation: close opened files and check for error while creating fil…
a99d3a7
…es (#8226) From: #8217 Closes: #6784 Thanks: @PrathyushaLakkireddy for the original patch.
Successfully merging a pull request may close this issue.
Problems
Noticed via an audit, the code from (*StandardLogWriter).PrintLogs() requests for *os.File but never closes it
cosmos-sdk/x/simulation/log.go
Lines 36 to 47 in 13b5a8d
We should be checking that the error returned after os.Create(filepath) checks an error and panics if non-nil
cosmos-sdk/x/simulation/log.go
Lines 61 to 64 in 13b5a8d
We need to fix that code in the 2 places as
For Admin Use
The text was updated successfully, but these errors were encountered: