diff options
author | Erik Schilling <ablu.erikschilling@googlemail.com> | 2013-08-20 18:56:10 +0200 |
---|---|---|
committer | Erik Schilling <ablu.erikschilling@googlemail.com> | 2013-08-26 22:56:48 +0200 |
commit | 64837cfccc3039fdd25d2e34c5f81949d34e1c95 (patch) | |
tree | d32cf93a01c6a5787ffbafb3d563654abab88f71 | |
parent | 81a88f1dd199691ce570ab124a43740b77a67f03 (diff) | |
download | manaserv-64837cfccc3039fdd25d2e34c5f81949d34e1c95.tar.gz manaserv-64837cfccc3039fdd25d2e34c5f81949d34e1c95.tar.bz2 manaserv-64837cfccc3039fdd25d2e34c5f81949d34e1c95.tar.xz manaserv-64837cfccc3039fdd25d2e34c5f81949d34e1c95.zip |
Secured the use of the AttributeInfo where nessecary
In some cases no longer existing attribute ids sent by the account
server or client were able to create crashs.
-rw-r--r-- | src/game-server/character.cpp | 3 | ||||
-rw-r--r-- | src/game-server/commandhandler.cpp | 6 | ||||
-rw-r--r-- | src/game-server/gamehandler.cpp | 17 |
3 files changed, 21 insertions, 5 deletions
diff --git a/src/game-server/character.cpp b/src/game-server/character.cpp index 7e49f0ab..82bb6c5d 100644 --- a/src/game-server/character.cpp +++ b/src/game-server/character.cpp @@ -140,7 +140,8 @@ void CharacterComponent::deserialize(Entity &entity, MessageIn &msg) unsigned id = msg.readInt16(); double base = msg.readDouble(); auto *attributeInfo = attributeManager->getAttributeInfo(id); - beingComponent->setAttribute(entity, attributeInfo, base); + if (attributeInfo) + beingComponent->setAttribute(entity, attributeInfo, base); } // status effects currently affecting the character diff --git a/src/game-server/commandhandler.cpp b/src/game-server/commandhandler.cpp index ca08a636..79758bcf 100644 --- a/src/game-server/commandhandler.cpp +++ b/src/game-server/commandhandler.cpp @@ -1126,6 +1126,12 @@ static void handleAttribute(Entity *player, std::string &args) auto *attribute = attributeManager->getAttributeInfo(attributeId); + if (!attribute) + { + say("Invalid attribute", player); + return; + } + // change the player's attribute beingComponent->setAttribute(*other, attribute, value); diff --git a/src/game-server/gamehandler.cpp b/src/game-server/gamehandler.cpp index e1f58967..1a0ca158 100644 --- a/src/game-server/gamehandler.cpp +++ b/src/game-server/gamehandler.cpp @@ -879,8 +879,12 @@ void GameHandler::handleRaiseAttribute(GameClient &client, MessageIn &message) const int attributeId = message.readInt16(); auto *attribute = attributeManager->getAttributeInfo(attributeId); AttribmodResponseCode retCode; - retCode = characterComponent->useCharacterPoint(*client.character, - attribute); + if (attribute) { + retCode = characterComponent->useCharacterPoint(*client.character, + attribute); + } else { + retCode = ATTRIBMOD_INVALID_ATTRIBUTE; + } MessageOut result(GPMSG_RAISE_ATTRIBUTE_RESPONSE); result.writeInt8(retCode); @@ -910,8 +914,13 @@ void GameHandler::handleLowerAttribute(GameClient &client, MessageIn &message) const int attributeId = message.readInt32(); auto *attribute = attributeManager->getAttributeInfo(attributeId); AttribmodResponseCode retCode; - retCode = characterComponent->useCorrectionPoint(*client.character, - attribute); + + if (attribute) { + retCode = characterComponent->useCorrectionPoint(*client.character, + attribute); + } else { + retCode = ATTRIBMOD_INVALID_ATTRIBUTE; + } MessageOut result(GPMSG_LOWER_ATTRIBUTE_RESPONSE); result.writeInt8(retCode); |