Skip to content

Commit b4dfc8d

Browse files
romanstinglerStephenCWills
authored andcommitted
Fix OOB read from unterminated player names in save/network data
1 parent b3e52b1 commit b4dfc8d

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

Source/pack.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ void UnPackPlayer(const PlayerPack &packed, Player &player)
367367
ClrPlrPath(player);
368368
player.destAction = ACTION_NONE;
369369

370-
CopyUtf8(player._pName, packed.pName, sizeof(player._pName));
370+
CopyUtf8(player._pName, std::string_view(packed.pName, PlayerNameLength), sizeof(player._pName));
371371

372372
InitPlayer(player, true);
373373

@@ -465,7 +465,7 @@ bool UnPackNetItem(const Player &player, const ItemNetPack &packedItem, Item &it
465465

466466
bool UnPackNetPlayer(const PlayerNetPack &packed, Player &player)
467467
{
468-
CopyUtf8(player._pName, packed.pName, sizeof(player._pName));
468+
CopyUtf8(player._pName, std::string_view(packed.pName, PlayerNameLength), sizeof(player._pName));
469469

470470
ValidateField(packed.pClass, packed.pClass < GetNumPlayerClasses());
471471
player._pClass = static_cast<HeroClass>(packed.pClass);

Source/pfile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ bool pfile_ui_set_hero_infos(bool (*uiAddHeroInfo)(_uiheroinfo *))
703703
if (ReadHero(*archive, &pkplr)) {
704704
_uiheroinfo uihero;
705705
uihero.saveNumber = i;
706-
strcpy(hero_names[i], pkplr.pName);
706+
CopyUtf8(hero_names[i], std::string_view(pkplr.pName, PlayerNameLength), sizeof(hero_names[i]));
707707
const bool hasSaveGame = ArchiveContainsGame(*archive);
708708
if (hasSaveGame)
709709
pkplr.bIsHellfire = gbIsHellfireSaveGame ? 1 : 0;

0 commit comments

Comments
 (0)