Skip to content

Commit 5006ce8

Browse files
committedJul 14, 2015
Remove raw message output on AOM deserialization failure
Improve TOCLIENT_ACTIVE_OBJECT_MESSAGES robustness for handling invalid data
1 parent 6f07f79 commit 5006ce8

File tree

2 files changed

+21
-36
lines changed

2 files changed

+21
-36
lines changed
 

Diff for: ‎src/environment.cpp

+12-17
Original file line numberDiff line numberDiff line change
@@ -2535,28 +2535,23 @@ void ClientEnvironment::removeActiveObject(u16 id)
25352535
m_active_objects.erase(id);
25362536
}
25372537

2538-
void ClientEnvironment::processActiveObjectMessage(u16 id,
2539-
const std::string &data)
2538+
void ClientEnvironment::processActiveObjectMessage(u16 id, const std::string &data)
25402539
{
2541-
ClientActiveObject* obj = getActiveObject(id);
2542-
if(obj == NULL)
2543-
{
2544-
infostream<<"ClientEnvironment::processActiveObjectMessage():"
2545-
<<" got message for id="<<id<<", which doesn't exist."
2546-
<<std::endl;
2540+
ClientActiveObject *obj = getActiveObject(id);
2541+
if (obj == NULL) {
2542+
infostream << "ClientEnvironment::processActiveObjectMessage():"
2543+
<< " got message for id=" << id << ", which doesn't exist."
2544+
<< std::endl;
25472545
return;
25482546
}
2549-
try
2550-
{
2547+
2548+
try {
25512549
obj->processMessage(data);
2552-
}
2553-
catch(SerializationError &e)
2554-
{
2550+
} catch (SerializationError &e) {
25552551
errorstream<<"ClientEnvironment::processActiveObjectMessage():"
2556-
<<" id="<<id<<" type="<<obj->getType()
2557-
<<" SerializationError in processMessage(),"
2558-
<<" message="<<serializeJsonString(data)
2559-
<<std::endl;
2552+
<< " id=" << id << " type=" << obj->getType()
2553+
<< " SerializationError in processMessage(): " << e.what()
2554+
<< std::endl;
25602555
}
25612556
}
25622557

Diff for: ‎src/network/clientpackethandler.cpp

+9-19
Original file line numberDiff line numberDiff line change
@@ -449,33 +449,23 @@ void Client::handleCommand_ActiveObjectMessages(NetworkPacket* pkt)
449449
string message
450450
}
451451
*/
452-
char buf[6];
453-
// Get all data except the command number
454452
std::string datastring(pkt->getString(0), pkt->getSize());
455-
// Throw them in an istringstream
456453
std::istringstream is(datastring, std::ios_base::binary);
457454

458455
try {
459-
while(is.eof() == false) {
460-
is.read(buf, 2);
461-
u16 id = readU16((u8*)buf);
462-
if (is.eof())
456+
while (is.good()) {
457+
u16 id = readU16(is);
458+
if (!is.good())
463459
break;
464-
is.read(buf, 2);
465-
size_t message_size = readU16((u8*)buf);
466-
std::string message;
467-
message.reserve(message_size);
468-
for (u32 i = 0; i < message_size; i++) {
469-
is.read(buf, 1);
470-
message.append(buf, 1);
471-
}
460+
461+
std::string message = deSerializeString(is);
462+
472463
// Pass on to the environment
473464
m_env.processActiveObjectMessage(id, message);
474465
}
475-
// Packet could be unreliable then ignore it
476-
} catch (PacketError &e) {
477-
infostream << "handleCommand_ActiveObjectMessages: " << e.what()
478-
<< ". The packet is unreliable, ignoring" << std::endl;
466+
} catch (SerializationError &e) {
467+
errorstream << "Client::handleCommand_ActiveObjectMessages: "
468+
<< "caught SerializationError: " << e.what() << std::endl;
479469
}
480470
}
481471

0 commit comments

Comments
 (0)
Please sign in to comment.