aboutsummaryrefslogtreecommitdiff
path: root/src/logging.cpp
diff options
context:
space:
mode:
authorWladimir J. van der Laan <[email protected]>2018-05-03 12:53:32 +0200
committerWladimir J. van der Laan <[email protected]>2018-05-03 12:53:57 +0200
commitb62b437acd4429ffe016187d2c817fbf73264beb (patch)
treee53831cbe5c440385466af45ac9244ea77066693 /src/logging.cpp
parentMerge #13154: Trivial: s/SetBestChain/ChainStateFlushed in comments after #13106 (diff)
parentlogging: remove unused return value from LogPrintStr (diff)
downloaddiscoin-b62b437acd4429ffe016187d2c817fbf73264beb.tar.xz
discoin-b62b437acd4429ffe016187d2c817fbf73264beb.zip
Merge #13148: logging: Fix potential use-after-free in LogPrintStr(...)
0bd4cd3 logging: remove unused return value from LogPrintStr (practicalswift) 76f344d logging: Fix potential use-after-free in LogPrintStr(...) (practicalswift) Pull request description: Fix potential use-after-free in `LogPrintStr(...)`. `freopen(…)` frees `m_fileout`. Tree-SHA512: ceee1f659c10a21525aa648377afeea0a37016339f5269dea54850ba3b475aa316f4931081655717b65f981598fdc9d79a1e79e55f7084c242eeb7bf372bc4b6
Diffstat (limited to 'src/logging.cpp')
-rw-r--r--src/logging.cpp17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/logging.cpp b/src/logging.cpp
index 10a3b1895..60d418fdb 100644
--- a/src/logging.cpp
+++ b/src/logging.cpp
@@ -198,15 +198,13 @@ std::string BCLog::Logger::LogTimestampStr(const std::string &str)
return strStamped;
}
-int BCLog::Logger::LogPrintStr(const std::string &str)
+void BCLog::Logger::LogPrintStr(const std::string &str)
{
- int ret = 0; // Returns total number of characters written
-
std::string strTimestamped = LogTimestampStr(str);
if (m_print_to_console) {
// print to console
- ret = fwrite(strTimestamped.data(), 1, strTimestamped.size(), stdout);
+ fwrite(strTimestamped.data(), 1, strTimestamped.size(), stdout);
fflush(stdout);
}
if (m_print_to_file) {
@@ -214,7 +212,6 @@ int BCLog::Logger::LogPrintStr(const std::string &str)
// buffer if we haven't opened the log yet
if (m_fileout == nullptr) {
- ret = strTimestamped.length();
m_msgs_before_open.push_back(strTimestamped);
}
else
@@ -222,14 +219,16 @@ int BCLog::Logger::LogPrintStr(const std::string &str)
// reopen the log file, if requested
if (m_reopen_file) {
m_reopen_file = false;
- if (fsbridge::freopen(m_file_path,"a",m_fileout) != nullptr)
- setbuf(m_fileout, nullptr); // unbuffered
+ m_fileout = fsbridge::freopen(m_file_path, "a", m_fileout);
+ if (!m_fileout) {
+ return;
+ }
+ setbuf(m_fileout, nullptr); // unbuffered
}
- ret = FileWriteStr(strTimestamped, m_fileout);
+ FileWriteStr(strTimestamped, m_fileout);
}
}
- return ret;
}
void BCLog::Logger::ShrinkDebugFile()