MCPcopy Create free account
hub / github.com/ElementsProject/elements / LogEscapeMessage

Function LogEscapeMessage

src/logging.cpp:328–339  ·  view source on GitHub ↗

Belts and suspenders: make sure outgoing log messages don't contain * potentially suspicious characters, such as terminal control codes. * * This escapes control characters except newline ('\n') in C syntax. * It escapes instead of removes them to still allow for troubleshooting * issues where they accidentally end up in strings. */

Source from the content-addressed store, hash-verified

326 * issues where they accidentally end up in strings.
327 */
328 std::string LogEscapeMessage(const std::string& str) {
329 std::string ret;
330 for (char ch_in : str) {
331 uint8_t ch = (uint8_t)ch_in;
332 if ((ch >= 32 || ch == '\n') && ch != '\x7f') {
333 ret += ch_in;
334 } else {
335 ret += strprintf("\\x%02x", ch);
336 }
337 }
338 return ret;
339 }
340} // namespace BCLog
341
342void BCLog::Logger::LogPrintStr(const std::string& str, const std::string& logging_function,

Callers 2

LogPrintStrMethod · 0.85
BOOST_AUTO_TEST_CASEFunction · 0.85

Calls

no outgoing calls

Tested by 1

BOOST_AUTO_TEST_CASEFunction · 0.68