common: sanitize message writer console output

(cherry picked from commit 52b33f4fb01bd54d936a016cbc63a4850daa3441)
This commit is contained in:
selsta
2026-10-04 18:50:24 -04:00
committed by such-gitea
parent 16d9fb5336
commit d46a6cd8c7
3 changed files with 11 additions and 6 deletions
+4 -3
View File
@@ -16,6 +16,7 @@
#define EASYLOGGING_CC
#include "easylogging++.h"
#include <cstdint>
#include <atomic>
#include <unistd.h>
@@ -2502,11 +2503,11 @@ void DefaultLogDispatchCallback::handle(const LogDispatchData* data) {
template<typename Transform>
static inline void utf8canonical(std::string &s, Transform t = [](wint_t c)->wint_t { return c; })
static inline void utf8canonical(std::string &s, Transform t = [](std::uint32_t c)->std::uint32_t { return c; })
{
size_t avail = s.size();
const char *ptr = s.data();
wint_t cp = 0;
std::uint32_t cp = 0;
int rbytes = 1, bytes = -1;
char wbuf[8], *wptr;
size_t w_offset = 0;
@@ -2585,7 +2586,7 @@ static inline void utf8canonical(std::string &s, Transform t = [](wint_t c)->win
void sanitize(std::string &s)
{
utf8canonical(s, [](wint_t c)->wint_t {
utf8canonical(s, [](std::uint32_t c)->std::uint32_t {
if (c == 9 || c == 10 || c == 13)
return c;
if (c < 0x20)
+1
View File
@@ -2791,6 +2791,7 @@ class Storage : base::NoCopy, public base::threading::ThreadSafe {
}
};
extern ELPP_EXPORT base::type::StoragePointer elStorage;
ELPP_EXPORT void sanitize(std::string& s);
#define ELPP el::base::Storage::getELPP()
class DefaultLogDispatchCallback : public LogDispatchCallback {
protected:
+6 -3
View File
@@ -99,17 +99,20 @@ public:
{
m_flush = false;
MCLOG_FILE(m_log_level, "msgwriter", m_oss.str());
std::string message = m_oss.str();
MCLOG_FILE(m_log_level, "msgwriter", message);
try { el::base::sanitize(message); }
catch (const std::exception&) { message = "<Invalid UTF-8 in message>"; }
PAUSE_READLINE();
if (epee::console_color_default == m_color)
{
std::cout << m_oss.str();
std::cout << message;
}
else
{
set_console_color(m_color, m_bright);
std::cout << m_oss.str();
std::cout << message;
epee::reset_console_color();
}
std::cout << std::endl;