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. */
| 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 | |
| 342 | void BCLog::Logger::LogPrintStr(const std::string& str, const std::string& logging_function, |
no outgoing calls