mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-20 16:53:10 +00:00
server: catch invalid utf8 exceptions
issue reported by coverity
This commit is contained in:
parent
c150a47e93
commit
fa54d659ef
@ -372,7 +372,16 @@ static lg::log_domain log_server("server");
|
||||
return true;
|
||||
}
|
||||
default_ban_times::const_iterator time_itor = ban_times_.find(duration);
|
||||
if (utf8::lowercase(duration) == "permanent" || duration == "0") {
|
||||
|
||||
std::string dur_lower;
|
||||
try {
|
||||
dur_lower = utf8::lowercase(duration);
|
||||
} catch ( utf8::invalid_utf8_exception & e ) {
|
||||
ERR_SERVER << "While parsing ban command duration string, caught an invalid utf8 exception: " << e.what() << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (dur_lower == "permanent" || duration == "0") {
|
||||
*time = 0;
|
||||
} else if (ban_times_.find(duration) != ban_times_.end()) {
|
||||
*time += time_itor->second;
|
||||
|
@ -1053,6 +1053,8 @@ void server::process_login(const network::connection sock,
|
||||
for (std::vector<std::string>::const_iterator d_it = disallowed_names_.begin();
|
||||
d_it != disallowed_names_.end(); ++d_it)
|
||||
{
|
||||
try {
|
||||
|
||||
if (utils::wildcard_string_match(utf8::lowercase(username),
|
||||
utf8::lowercase(*d_it)))
|
||||
{
|
||||
@ -1060,6 +1062,10 @@ void server::process_login(const network::connection sock,
|
||||
MP_NAME_RESERVED_ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
} catch ( utf8::invalid_utf8_exception & e ) {
|
||||
ERR_SERVER << "While checking a username vs a list of disallowed names, caught an invalid utf8 exception: " << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
// If this is a request for password reminder
|
||||
@ -1377,6 +1383,9 @@ std::string server::process_command(std::string query, std::string issuer_name)
|
||||
}
|
||||
|
||||
const std::string::iterator i = std::find(query.begin(), query.end(), ' ');
|
||||
|
||||
try {
|
||||
|
||||
const std::string command = utf8::lowercase(std::string(query.begin(), i));
|
||||
std::string parameters = (i == query.end() ? "" : std::string(i + 1, query.end()));
|
||||
utils::strip(parameters);
|
||||
@ -1392,10 +1401,18 @@ std::string server::process_command(std::string query, std::string issuer_name)
|
||||
} catch (boost::bad_function_call & ex) {
|
||||
ERR_SERVER << "While handling a command '" << command << "', caught a boost::bad_function_call exception.\n";
|
||||
ERR_SERVER << ex.what() << std::endl;
|
||||
out << "An internal server error occurred (boost::bad_function_call) while executing '" << command << "'\n";
|
||||
}
|
||||
}
|
||||
|
||||
return out.str();
|
||||
|
||||
} catch ( utf8::invalid_utf8_exception & e ) {
|
||||
std::string msg = "While handling a command, caught an invalid utf8 exception: ";
|
||||
msg += e.what();
|
||||
ERR_SERVER << msg << std::endl;
|
||||
return (msg + '\n');
|
||||
}
|
||||
}
|
||||
|
||||
// Shutdown, restart and sample commands can only be issued via the socket.
|
||||
@ -1499,11 +1516,17 @@ void server::netstats_handler(const std::string& /*issuer_name*/, const std::str
|
||||
<< stats.npending_sends << "\nBytes in buffers: "
|
||||
<< stats.nbytes_pending_sends << "\n";
|
||||
|
||||
try {
|
||||
|
||||
if (utf8::lowercase(parameters) == "all") {
|
||||
*out << network::get_bandwidth_stats_all();
|
||||
} else {
|
||||
*out << network::get_bandwidth_stats(); // stats from previuos hour
|
||||
}
|
||||
|
||||
} catch ( utf8::invalid_utf8_exception & e ) {
|
||||
ERR_SERVER << "While handling a netstats command, caught an invalid utf8 exception: " << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void server::adminmsg_handler(const std::string& issuer_name, const std::string& /*query*/, std::string& parameters, std::ostringstream *out) {
|
||||
@ -1671,6 +1694,9 @@ void server::clones_handler(const std::string& /*issuer_name*/, const std::strin
|
||||
void server::bans_handler(const std::string& /*issuer_name*/, const std::string& /*query*/, std::string& parameters, std::ostringstream *out) {
|
||||
assert(out != NULL);
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
if (parameters.empty()) {
|
||||
ban_manager_.list_bans(*out);
|
||||
} else if (utf8::lowercase(parameters) == "deleted") {
|
||||
@ -1681,6 +1707,10 @@ void server::bans_handler(const std::string& /*issuer_name*/, const std::string&
|
||||
} else {
|
||||
ban_manager_.list_bans(*out, utils::strip(parameters));
|
||||
}
|
||||
|
||||
} catch ( utf8::invalid_utf8_exception & e ) {
|
||||
ERR_SERVER << "While handling bans, caught an invalid utf8 exception: " << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void server::ban_handler(const std::string& issuer_name, const std::string& /*query*/, std::string& parameters, std::ostringstream *out) {
|
||||
@ -2014,12 +2044,18 @@ void server::searchlog_handler(const std::string& /*issuer_name*/, const std::st
|
||||
void server::dul_handler(const std::string& /*issuer_name*/, const std::string& /*query*/, std::string& parameters, std::ostringstream *out) {
|
||||
assert(out != NULL);
|
||||
|
||||
try {
|
||||
|
||||
if (parameters == "") {
|
||||
*out << "Unregistered login is " << (deny_unregistered_login_ ? "disallowed" : "allowed") << ".";
|
||||
} else {
|
||||
deny_unregistered_login_ = (utf8::lowercase(parameters) == "yes");
|
||||
*out << "Unregistered login is now " << (deny_unregistered_login_ ? "disallowed" : "allowed") << ".";
|
||||
}
|
||||
|
||||
} catch ( utf8::invalid_utf8_exception & e ) {
|
||||
ERR_SERVER << "While handling dul (deny unregistered logins), caught an invalid utf8 exception: " << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void server::process_nickserv(const network::connection sock, simple_wml::node& data) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user