From 3ad899c75889a941634deccb55a947aa79c58366 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Wed, 30 Oct 2019 12:26:46 +1100 Subject: [PATCH] Avoid crash in JSON library for invalid UTF8 --- lib/MySQL_Logger.cpp | 4 ++-- lib/MySQL_Session.cpp | 2 +- lib/MySQL_Thread.cpp | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/MySQL_Logger.cpp b/lib/MySQL_Logger.cpp index a5d27b254..73ec7c09c 100644 --- a/lib/MySQL_Logger.cpp +++ b/lib/MySQL_Logger.cpp @@ -229,7 +229,7 @@ void MySQL_Event::write_auth(std::fstream *f, MySQL_Session *sess) { // for performance reason, we are moving the write lock // right before the write to disk GloMyLogger->wrlock(); - *f << j.dump() << std::endl; + *f << j.dump(-1, ' ', false, json::error_handler_t::replace) << std::endl; } uint64_t MySQL_Event::write_query_format_1(std::fstream *f) { @@ -402,7 +402,7 @@ uint64_t MySQL_Event::write_query_format_2_json(std::fstream *f) { // right before the write to disk GloMyLogger->wrlock(); - *f << j.dump() << std::endl; + *f << j.dump(-1, ' ', false, json::error_handler_t::replace) << std::endl; return total_bytes; // always 0 } diff --git a/lib/MySQL_Session.cpp b/lib/MySQL_Session.cpp index f3d0b7f6b..848a32417 100644 --- a/lib/MySQL_Session.cpp +++ b/lib/MySQL_Session.cpp @@ -1050,7 +1050,7 @@ void MySQL_Session::return_proxysql_internal(PtrSize_t *pkt) { if (pkt->size==(5+l) && strncasecmp((char *)"PROXYSQL INTERNAL SESSION", (char *)pkt->ptr+5, l)==0) { json j; generate_proxysql_internal_session_json(j); - std::string s = j.dump(4); + std::string s = j.dump(4, ' ', false, json::error_handler_t::replace); SQLite3_result *resultset = new SQLite3_result(1); resultset->add_column_definition(SQLITE_TEXT,"session_info"); char *pta[1]; diff --git a/lib/MySQL_Thread.cpp b/lib/MySQL_Thread.cpp index cc0801874..8f9bb96e6 100644 --- a/lib/MySQL_Thread.cpp +++ b/lib/MySQL_Thread.cpp @@ -5564,10 +5564,10 @@ SQLite3_result * MySQL_Threads_Handler::SQL3_Processlist() { json j; sess->generate_proxysql_internal_session_json(j); if (mysql_thread___show_processlist_extended == 2) { - std::string s = j.dump(4); + std::string s = j.dump(4, ' ', false, json::error_handler_t::replace); pta[15] = strdup(s.c_str()); } else { - std::string s = j.dump(); + std::string s = j.dump(-1, ' ', false, json::error_handler_t::replace); pta[15] = strdup(s.c_str()); } }