Skip to content

Commit

Permalink
fix UB caused by invalid GC id, set GC rank when changing gc if one i…
Browse files Browse the repository at this point in the history
…snt set - fixes #472
  • Loading branch information
NotAdam committed Jan 28, 2019
1 parent ac709c5 commit 72ca7b6
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/world/Network/Handlers/GMCommandHandlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,13 +399,38 @@ void Sapphire::Network::GameConnection::gm1Handler( FrameworkPtr pFw,
}
case GmCommand::GC:
{
if( param1 > 3 )
{
player.sendUrgent( "Invalid Grand Company ID: {0}", param1 );
return;
}

targetPlayer->setGc( param1 );

// if we're changing them to a GC, check if they have a rank and if not, set it to the lowest rank
if( param1 > 0 )
{
auto gcRankIdx = static_cast< uint8_t >( param1 ) - 1;
if( targetPlayer->getGcRankArray()[ gcRankIdx ] == 0 )
{
player.setGcRankAt( gcRankIdx, 1 );
}
}

player.sendNotice( "GC for {0} was set to {1}", targetPlayer->getName(), targetPlayer->getGc() );
break;
}
case GmCommand::GCRank:
{
targetPlayer->setGcRankAt( targetPlayer->getGc() - 1, param1 );
auto gcId = targetPlayer->getGc() - 1;

if( gcId > 2 )
{
player.sendUrgent( "{0} has an invalid Grand Company ID: {0}", targetPlayer->getName(), gcId );
return;
}

targetPlayer->setGcRankAt( gcId, param1 );
player.sendNotice( "GC Rank for {0} for GC {1} was set to {2}", targetPlayer->getName(), targetPlayer->getGc(),
targetPlayer->getGcRankArray()[ targetPlayer->getGc() - 1 ] );
break;
Expand Down

0 comments on commit 72ca7b6

Please sign in to comment.