1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-01 17:38:41 +00:00

Sanitize lang_code and full_version received from client

fixes #14262
This commit is contained in:
sfan5 2024-01-15 22:34:27 +01:00
parent bdc124ba41
commit e8008c1b21
2 changed files with 25 additions and 13 deletions

View file

@ -33,6 +33,18 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "util/srp.h"
#include "face_position_cache.h"
static std::string string_sanitize_ascii(const std::string &s, u32 max_length)
{
std::string out;
for (char c : s) {
if (out.size() >= max_length)
break;
if (c > 32 && c < 127)
out.push_back(c);
}
return out;
}
const char *ClientInterface::statenames[] = {
"Invalid",
"Disconnecting",
@ -46,8 +58,6 @@ const char *ClientInterface::statenames[] = {
"SudoMode",
};
std::string ClientInterface::state2Name(ClientState state)
{
return statenames[state];
@ -639,9 +649,17 @@ void RemoteClient::resetChosenMech()
chosen_mech = AUTH_MECHANISM_NONE;
}
u64 RemoteClient::uptime() const
void RemoteClient::setVersionInfo(u8 major, u8 minor, u8 patch, const std::string &full)
{
return porting::getTimeS() - m_connection_time;
m_version_major = major;
m_version_minor = minor;
m_version_patch = patch;
m_full_version = string_sanitize_ascii(full, 64);
}
void RemoteClient::setLangCode(const std::string &code)
{
m_lang_code = string_sanitize_ascii(code, 12);
}
ClientInterface::ClientInterface(const std::shared_ptr<con::Connection> & con)