Console: don't let random unformatted data end up in the log
This commit is contained in:
@@ -380,7 +380,7 @@ void ConsoleCommands::process_input(std::string& command, const char* data, uint
|
||||
command[k] = '\0';
|
||||
|
||||
if (check_cookie && ((k <= m_cookie.length()) || (memcmp(command.data(), m_cookie.data(), m_cookie.length()) != 0))) {
|
||||
LOGWARN(4, "cookie check failed, skipping command " << command);
|
||||
LOGWARN(4, "cookie check failed, skipping command " << log::MaskNonASCII(command));
|
||||
}
|
||||
else {
|
||||
if (check_cookie) {
|
||||
@@ -410,7 +410,7 @@ void ConsoleCommands::process_input(std::string& command, const char* data, uint
|
||||
}
|
||||
|
||||
if (!c->name.len) {
|
||||
LOGWARN(0, "Unknown command " << command.c_str());
|
||||
LOGWARN(0, "Unknown command " << log::MaskNonASCII(command));
|
||||
do_help(nullptr, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
27
src/log.h
27
src/log.h
@@ -449,12 +449,37 @@ struct EscapedString
|
||||
}
|
||||
}
|
||||
|
||||
FORCEINLINE operator const std::string&() const { return m_data; }
|
||||
|
||||
private:
|
||||
std::string m_data;
|
||||
};
|
||||
|
||||
template<> struct log::Stream::Entry<EscapedString>
|
||||
{
|
||||
static FORCEINLINE void put(const EscapedString& value, Stream* wrapper) { *wrapper << value.m_data; }
|
||||
static FORCEINLINE void put(const EscapedString& value, Stream* wrapper) { *wrapper << value; }
|
||||
};
|
||||
|
||||
struct MaskNonASCII
|
||||
{
|
||||
explicit FORCEINLINE MaskNonASCII(const std::string& data, char mask_character = '?') : m_data(data)
|
||||
{
|
||||
for (char& c : m_data) {
|
||||
if ((c < 32) || (c >= 127)) {
|
||||
c = mask_character;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FORCEINLINE operator const std::string&() const { return m_data; }
|
||||
|
||||
private:
|
||||
std::string m_data;
|
||||
};
|
||||
|
||||
template<> struct log::Stream::Entry<MaskNonASCII>
|
||||
{
|
||||
static FORCEINLINE void put(const MaskNonASCII& value, Stream* wrapper) { *wrapper << value; }
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
|
||||
Reference in New Issue
Block a user