From ab8ac1cd99a489e615b34fd0f80963697da12deb Mon Sep 17 00:00:00 2001 From: Luke1410 Date: Sat, 2 Jun 2018 23:16:16 +0200 Subject: [PATCH] - fix edge case of a non-null-terminated string --- DependentExtensions/IrrlichtDemo/RakNetStuff.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/DependentExtensions/IrrlichtDemo/RakNetStuff.cpp b/DependentExtensions/IrrlichtDemo/RakNetStuff.cpp index 9f6a44f8f..8a07d3478 100644 --- a/DependentExtensions/IrrlichtDemo/RakNetStuff.cpp +++ b/DependentExtensions/IrrlichtDemo/RakNetStuff.cpp @@ -228,7 +228,9 @@ void PlayerReplica::PostDeserializeConstruction(RakNet::BitStream *constructionB model->setVisible(true); model->setAnimationEndCallback(this); wchar_t playerNameWChar[1024]; - mbstowcs(playerNameWChar, playerName.C_String(), 1024); + mbstowcs(playerNameWChar, playerName.C_String(), 1023); + // ensure wide-character string is null terminated (i.e. if playerName length is >= 1023) + playerNameWChar[1023] = L'\0'; scene::IBillboardSceneNode *bb = sm->addBillboardTextSceneNode(0, playerNameWChar, model); bb->setSize(core::dimension2df(40,20)); bb->setPosition(core::vector3df(0,model->getBoundingBox().MaxEdge.Y+bb->getBoundingBox().MaxEdge.Y-bb->getBoundingBox().MinEdge.Y+5.0,0));