summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2019-09-09 15:41:09 +0200
committerMiklos Vajna <vmiklos@collabora.com>2019-09-09 15:41:09 +0200
commita7d836dd7c2903e40e5a29da34b581d65b28fd84 (patch)
treeb6b81508847f1f9d76b6ec6ffd33c8e913014623 /common
parent0189fb10fb00b7a0baeede8a3eb6ea191515d5af (diff)
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
Diffstat (limited to 'common')
-rw-r--r--common/Log.cpp7
-rw-r--r--common/Log.hpp20
2 files changed, 18 insertions, 9 deletions
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); \
} \