Fixed a server side bug with could cause invalid utf-8 being sent to a client.

This is a part of the fix for CVE-2007-3917, commits 
2007-10-01T12:13:24Z!koraq@xs4all.nl and 2007-10-01T15:37:05Z!koraq@xs4all.nl are also part of the fix.
This commit is contained in:
Mark de Wever 2007-10-01 18:58:21 +00:00
parent 7bdce717c3
commit d364bd2968
2 changed files with 6 additions and 2 deletions

View file

@ -37,6 +37,8 @@ Version 1.3.8+svn:
* minimum number of turns reduced to 1
* new option to allow female leaders by default instead of male leaders
* fixed a crash if the client recieves invalid utf-8
* fixed a server side bug with could cause invalid utf-8 being send to a
client.
* units:
* balancing changes:
* created undead variations for the 'bat' and 'gryphon' race

View file

@ -82,9 +82,11 @@ config construct_server_message(const std::string& message, const game& g)
void truncate_message(t_string& str)
{
const size_t max_message_length = 256;
std::string newstr = str.str();
// The string send can contain utf-8 so truncate as wide_string otherwise
// an corrupted utf-8 string can be returned.
wide_string newstr = utils::string_to_wstring(str.str());
newstr.resize(minimum<size_t>(str.size(),max_message_length));
str = newstr;
str = utils::wstring_to_string(newstr);
}
} // end anon namespace