simplewallet: report file writing failure for export_transfers command
What changed, and why it matters
This commit fixes a minor user-experience issue in Monero's command-line wallet. Previously, when you ran the export_transfers command, the wallet would always say the CSV file was exported successfully even if the file could not actually be written (for example, because of missing permissions or a full disk). Now it checks whether the file opened and whether writing succeeded, and reports a clear failure message instead of falsely claiming success.
No urgent action needed. Treat as a normal quality/UX fix. Users who rely on exported CSVs should verify file output when running older wallet versions.
Security signals we found
Incorrect success reporting after a potentially failed file operation
Missing error handling on std::ofstream open and write
Evidence from the diff
The patch adds two std::ofstream::fail() checks in simple_wallet::export_transfers. The first check returns early with an error if the output file cannot be opened. The second check, after file.close(), reports failure if any write operation failed. Previously the function unconditionally printed a success message. This is a robustness fix, not a memory-safety or cryptographic bug.
Changed components
src/simplewallet/simplewallet.cppsimple_wallet::export_transfersInspect captured patch +9 / −1
diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp
index 6324e3c..8954aa3 100644
--- a/src/simplewallet/simplewallet.cpp
+++ b/src/simplewallet/simplewallet.cpp
@@ -8768,6 +8768,10 @@ bool simple_wallet::export_transfers(const std::vector<std::string>& args_)
}
std::ofstream file(filename);
+ if(file.fail()) {
+ fail_msg_writer() << boost::format(tr("Failed to open %s for writing")) % filename;
+ return true;
+ }
// header
file <<
@@ -8837,7 +8841,11 @@ bool simple_wallet::export_transfers(const std::vector<std::string>& args_)
}
file.close();
- success_msg_writer() << tr("CSV exported to ") << filename;
+ if(file.fail()) {
+ fail_msg_writer() << tr("Failed to export CSV to ") << filename;
+ } else {
+ success_msg_writer() << tr("CSV exported to ") << filename;
+ }
return true;
}
Why this scored 17/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.