Skip to content
New issue

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

cmd/gnoland: execBalancesExport leaks the opened file and at no point closes it #3032

Open
odeke-em opened this issue Oct 27, 2024 · 1 comment
Assignees
Labels
security Security-sensitive issue

Comments

@odeke-em
Copy link

Reading through this code

func execBalancesExport(cfg *balancesCfg, io commands.IO, args []string) error {
// Load the genesis
genesis, loadErr := types.GenesisDocFromFile(cfg.genesisPath)
if loadErr != nil {
return fmt.Errorf("unable to load genesis, %w", loadErr)
}
// Load the genesis state
if genesis.AppState == nil {
return errAppStateNotSet
}
state := genesis.AppState.(gnoland.GnoGenesisState)
if len(state.Balances) == 0 {
io.Println("No genesis balances to export")
return nil
}
// Make sure the output file path is specified
if len(args) == 0 {
return errNoOutputFile
}
// Open output file
outputFile, err := os.OpenFile(
args[0],
os.O_RDWR|os.O_CREATE|os.O_APPEND,
0o755,
)
if err != nil {
return fmt.Errorf("unable to create output file, %w", err)
}
// Save the balances
for _, balance := range state.Balances {
if _, err = outputFile.WriteString(
fmt.Sprintf("%s\n", balance),
); err != nil {
return fmt.Errorf("unable to write to output, %w", err)
}
}
io.Printfln(
"Exported %d balances",
len(state.Balances),
)
return nil
}

at no point is the file that's opened per

outputFile, err := os.OpenFile(

ever closed

@kristovatlas kristovatlas self-assigned this Oct 29, 2024
@kristovatlas kristovatlas added the security Security-sensitive issue label Oct 29, 2024
@kristovatlas
Copy link
Contributor

Thanks for the report, @odeke-em. We're looking into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
security Security-sensitive issue
Projects
Status: Triage
Development

No branches or pull requests

2 participants