[Libreoffice-commits] online.git: common/Log.cpp common/Log.hpp
Miklos Vajna (via logerrit)
logerrit at kemper.freedesktop.org
Mon Sep 9 13:42:47 UTC 2019
common/Log.cpp | 7 +++++++
common/Log.hpp | 20 +++++++++++---------
2 files changed, 18 insertions(+), 9 deletions(-)
New commits:
commit a7d836dd7c2903e40e5a29da34b581d65b28fd84
Author: Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Mon Sep 9 15:41:09 2019 +0200
Commit: Miklos Vajna <vmiklos at collabora.com>
CommitDate: Mon Sep 9 15:41:09 2019 +0200
Fix UB in unit-wopi
net/Socket.hpp:405:9: runtime error: member call on address 0x6070007a2210 which does not point to an object of type 'Poco::Logger'
0x6070007a2210: note: object has invalid vptr
05 00 80 0e 7c 01 80 6f 3c 7f 00 00 c8 b8 0f 01 3c 7f 00 00 00 00 00 00 be be be be 38 22 7a 00
^~~~~~~~~~~~~~~~~~~~~~~
invalid vptr
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior net/Socket.hpp:405:9 in
Which is use-after-free: once Poco::Logger::shutdown() is called, we
need to tolerate LOG_DBG() and other similar calls, even if they don't
go anywhere.
Change-Id: Ic76433743177dd2b604ff34e340309c506d83350
diff --git a/common/Log.cpp b/common/Log.cpp
index 4441eb785..1abb81d28 100644
--- a/common/Log.cpp
+++ b/common/Log.cpp
@@ -74,6 +74,7 @@ namespace Log
Poco::Logger* getLogger() { return _logger; }
};
static StaticNameHelper Source;
+ bool IsShutdown = false;
// We need a signal safe means of writing messages
// $ man 7 signal
@@ -216,6 +217,7 @@ namespace Log
void shutdown()
{
logger().shutdown();
+ IsShutdown = true;
// Flush
std::flush(std::cout);
@@ -224,6 +226,11 @@ namespace Log
fflush(stderr);
}
#endif
+
+ bool isShutdown()
+ {
+ return IsShutdown;
+ }
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/common/Log.hpp b/common/Log.hpp
index fc0408088..6690c01bc 100644
--- a/common/Log.hpp
+++ b/common/Log.hpp
@@ -59,6 +59,8 @@ namespace Log
#if !MOBILEAPP
/// Shutdown and release the logging system.
void shutdown();
+ /// Was shutdown() called?
+ bool isShutdown();
#endif
char* prefix(char* buffer, std::size_t len, const char* level);
@@ -289,7 +291,7 @@ namespace Log
do \
{ \
auto &log_ = Log::logger(); \
- if (log_.trace()) \
+ if (!Log::isShutdown() && log_.trace()) \
{ \
LOG_BODY_(log_, TRACE, "TRC", X, true); \
} \
@@ -299,7 +301,7 @@ namespace Log
do \
{ \
auto &log_ = Log::logger(); \
- if (log_.trace()) \
+ if (!Log::isShutdown() && log_.trace()) \
{ \
LOG_BODY_(log_, TRACE, "TRC", X, false);\
} \
@@ -309,7 +311,7 @@ namespace Log
do \
{ \
auto &log_ = Log::logger(); \
- if (log_.debug()) \
+ if (!Log::isShutdown() && log_.debug()) \
{ \
LOG_BODY_(log_, DEBUG, "DBG", X, true); \
} \
@@ -319,7 +321,7 @@ namespace Log
do \
{ \
auto &log_ = Log::logger(); \
- if (log_.information()) \
+ if (!Log::isShutdown() && log_.information()) \
{ \
LOG_BODY_(log_, INFORMATION, "INF", X, true); \
} \
@@ -329,7 +331,7 @@ namespace Log
do \
{ \
auto &log_ = Log::logger(); \
- if (log_.warning()) \
+ if (!Log::isShutdown() && log_.warning()) \
{ \
LOG_BODY_(log_, WARNING, "WRN", X, true); \
} \
@@ -339,7 +341,7 @@ namespace Log
do \
{ \
auto &log_ = Log::logger(); \
- if (log_.error()) \
+ if (!Log::isShutdown() && log_.error()) \
{ \
LOG_BODY_(log_, ERROR, "ERR", X, true); \
} \
@@ -349,7 +351,7 @@ namespace Log
do \
{ \
auto &log_ = Log::logger(); \
- if (log_.error()) \
+ if (!Log::isShutdown() && log_.error()) \
{ \
LOG_BODY_(log_, ERROR, "ERR", X << " (" << Util::symbolicErrno(errno) << ": " << std::strerror(errno) << ")", true); \
} \
@@ -360,7 +362,7 @@ namespace Log
{ \
std::cerr << X << std::endl; \
auto &log_ = Log::logger(); \
- if (log_.fatal()) \
+ if (!Log::isShutdown() && log_.fatal()) \
{ \
LOG_BODY_(log_, FATAL, "FTL", X, true); \
} \
@@ -370,7 +372,7 @@ namespace Log
do \
{ \
auto &log_ = Log::logger(); \
- if (log_.error()) \
+ if (!Log::isShutdown() && log_.error()) \
{ \
LOG_BODY_(log_, FATAL, "FTL", X << " (" << Util::symbolicErrno(errno) << ": " << std::strerror(errno) << ")", true); \
} \
More information about the Libreoffice-commits
mailing list