From 3216422307688e707fd80ee8dc11e375fa30d3fc Mon Sep 17 00:00:00 2001 From: AlexVinS Date: Sun, 27 Nov 2016 22:07:01 +0300 Subject: [PATCH] Fixed a few CWE-457 --- client/CMT.cpp | 5 ----- lib/CArtHandler.cpp | 3 +++ lib/CArtHandler.h | 13 ++++++------- lib/CCreatureHandler.cpp | 8 +++++++- lib/CGameState.cpp | 5 +++-- lib/CGameStateFwd.h | 4 +++- lib/CHeroHandler.cpp | 2 +- lib/CModHandler.cpp | 14 ++++++++++++++ lib/CModHandler.h | 2 +- lib/CPathfinder.cpp | 5 +++++ lib/CTownHandler.cpp | 9 +++++++++ lib/CTownHandler.h | 2 ++ lib/NetPacksBase.h | 1 + lib/NetPacksLib.cpp | 1 + lib/VCMI_Lib.cpp | 3 +-- lib/VCMI_Lib.h | 4 ++-- lib/mapObjects/CBank.cpp | 2 ++ lib/mapObjects/CGPandoraBox.cpp | 13 +++++++++++++ lib/mapObjects/CGPandoraBox.h | 4 ++-- lib/mapObjects/CObjectClassesHandler.cpp | 11 +++++++++++ lib/mapObjects/CObjectClassesHandler.h | 4 ++-- lib/mapObjects/CRewardableObject.cpp | 1 + lib/mapObjects/CommonConstructors.cpp | 3 +++ 23 files changed, 93 insertions(+), 26 deletions(-) diff --git a/client/CMT.cpp b/client/CMT.cpp index 40afec038..5e69e36f6 100644 --- a/client/CMT.cpp +++ b/client/CMT.cpp @@ -667,11 +667,6 @@ void processCommand(const std::string &message) { vm.insert(std::pair("onlyAI", po::variable_value())); } - else if (cn == "ai") - { - VLC->IS_AI_ENABLED = !VLC->IS_AI_ENABLED; - std::cout << "Current AI status: " << (VLC->IS_AI_ENABLED ? "enabled" : "disabled") << std::endl; - } else if(cn == "mp" && adventureInt) { if(const CGHeroInstance *h = dynamic_cast(adventureInt->selection)) diff --git a/lib/CArtHandler.cpp b/lib/CArtHandler.cpp index 11ef44155..3d3a1cadb 100644 --- a/lib/CArtHandler.cpp +++ b/lib/CArtHandler.cpp @@ -76,6 +76,9 @@ CArtifact::CArtifact() possibleSlots[ArtBearer::HERO]; //we want to generate map entry even if it will be empty possibleSlots[ArtBearer::CREATURE]; //we want to generate map entry even if it will be empty possibleSlots[ArtBearer::COMMANDER]; + iconIndex = ArtifactID::NONE; + price = 0; + aClass = ART_SPECIAL; } CArtifact::~CArtifact() diff --git a/lib/CArtHandler.h b/lib/CArtHandler.h index 3492b5a5a..8b696b14d 100644 --- a/lib/CArtHandler.h +++ b/lib/CArtHandler.h @@ -54,6 +54,12 @@ public: std::string large; // big image for cutom artifacts, used in drag & drop std::string advMapDef; //used for adventure map object si32 iconIndex; + ui32 price; + std::map > possibleSlots; //Bearer Type => ids of slots where artifact can be placed + std::unique_ptr > constituents; // Artifacts IDs a combined artifact consists of, or nullptr. + std::vector constituentOf; // Reverse map of constituents - combined arts that include this art + EartClass aClass; + ArtifactID id; const std::string &Name() const; //getter const std::string &Description() const; //getter @@ -68,13 +74,6 @@ public: virtual void levelUpArtifact (CArtifactInstance * art){}; - ui32 price; - std::map > possibleSlots; //Bearer Type => ids of slots where artifact can be placed - std::unique_ptr > constituents; // Artifacts IDs a combined artifact consists of, or nullptr. - std::vector constituentOf; // Reverse map of constituents - combined arts that include this art - EartClass aClass; - ArtifactID id; - template void serialize(Handler &h, const int version) { h & static_cast(*this); diff --git a/lib/CCreatureHandler.cpp b/lib/CCreatureHandler.cpp index e26aeb26a..32ba33953 100644 --- a/lib/CCreatureHandler.cpp +++ b/lib/CCreatureHandler.cpp @@ -105,9 +105,15 @@ si32 CCreature::maxAmount(const std::vector &res) const //how many creatur CCreature::CCreature() { - doubleWide = false; setNodeType(CBonusSystemNode::CREATURE); + faction = 0; + level = 0; + fightValue = AIValue = growth = hordeGrowth = ammMin = ammMax = 0; + doubleWide = false; + special = true; + iconIndex = -1; } + void CCreature::addBonus(int val, Bonus::BonusType type, int subtype /*= -1*/) { auto added = std::make_shared(Bonus::PERMANENT, type, Bonus::CREATURE_ABILITY, val, idNumber, subtype, Bonus::BASE_NUMBER); diff --git a/lib/CGameState.cpp b/lib/CGameState.cpp index baec8a204..51c535cc2 100644 --- a/lib/CGameState.cpp +++ b/lib/CGameState.cpp @@ -656,6 +656,7 @@ CGameState::CGameState() //objCaller = new CObjectCallersHandler; globalEffects.setDescription("Global effects"); globalEffects.setNodeType(CBonusSystemNode::GLOBAL_EFFECTS); + day = 0; } CGameState::~CGameState() @@ -2866,8 +2867,8 @@ CGHeroInstance * CGameState::getUsedHero(HeroTypeID hid) const } PlayerState::PlayerState() - : color(-1), enteredWinningCheatCode(0), - enteredLosingCheatCode(0), status(EPlayerStatus::INGAME) + : color(-1), human(false), enteredWinningCheatCode(false), + enteredLosingCheatCode(false), status(EPlayerStatus::INGAME) { setNodeType(PLAYER); } diff --git a/lib/CGameStateFwd.h b/lib/CGameStateFwd.h index b2c4a249d..d79089e32 100644 --- a/lib/CGameStateFwd.h +++ b/lib/CGameStateFwd.h @@ -173,7 +173,9 @@ struct DLL_LINKAGE QuestInfo //universal interface for human and AI const CGObjectInstance * obj; //related object, most likely Seer Hut int3 tile; - QuestInfo(){}; + QuestInfo() + : quest(nullptr), obj(nullptr), tile(-1,-1,-1) + {}; QuestInfo (const CQuest * Quest, const CGObjectInstance * Obj, int3 Tile) : quest (Quest), obj (Obj), tile (Tile){}; diff --git a/lib/CHeroHandler.cpp b/lib/CHeroHandler.cpp index 3cf76d536..02c08b1af 100644 --- a/lib/CHeroHandler.cpp +++ b/lib/CHeroHandler.cpp @@ -59,7 +59,7 @@ EAlignment::EAlignment CHeroClass::getAlignment() const } CHeroClass::CHeroClass() - : commander(nullptr) + : faction(0), id(0), affinity(0), defaultTavernChance(0), commander(nullptr) { } diff --git a/lib/CModHandler.cpp b/lib/CModHandler.cpp index ae0496e84..6d26f26a1 100644 --- a/lib/CModHandler.cpp +++ b/lib/CModHandler.cpp @@ -486,12 +486,22 @@ JsonNode addMeta(JsonNode config, std::string meta) return config; } +CModInfo::CModInfo(): + checksum(0), + enabled(false), + validation(PENDING) +{ + +} + CModInfo::CModInfo(std::string identifier,const JsonNode & local, const JsonNode & config): identifier(identifier), name(config["name"].String()), description(config["description"].String()), dependencies(config["depends"].convertTo >()), conflicts(config["conflicts"].convertTo >()), + checksum(0), + enabled(false), validation(PENDING), config(addMeta(config, identifier)) { @@ -554,6 +564,10 @@ void CModInfo::loadLocalData(const JsonNode & data) CModHandler::CModHandler() { + modules.COMMANDERS = false; + modules.STACK_ARTIFACT = false; + modules.STACK_EXP = false; + modules.MITHRIL = false; for (int i = 0; i < GameConstants::RESOURCE_QUANTITY; ++i) { identifiers.registerObject("core", "resource", GameConstants::RESOURCE_NAMES[i], i); diff --git a/lib/CModHandler.h b/lib/CModHandler.h index 0e26bc06f..1a8df6e63 100644 --- a/lib/CModHandler.h +++ b/lib/CModHandler.h @@ -191,7 +191,7 @@ public: JsonNode config; - CModInfo(){} + CModInfo(); CModInfo(std::string identifier, const JsonNode & local, const JsonNode & config); JsonNode saveLocalData() const; diff --git a/lib/CPathfinder.cpp b/lib/CPathfinder.cpp index 9a0b22cc3..8b0b3e92c 100644 --- a/lib/CPathfinder.cpp +++ b/lib/CPathfinder.cpp @@ -43,6 +43,11 @@ CPathfinder::CPathfinder(CPathsInfo & _out, CGameState * _gs, const CGHeroInstan assert(hero); assert(hero == getHero(hero->id)); + cp = dp = nullptr; + ct = dt = nullptr; + ctObj = dtObj = nullptr; + destAction = CGPathNode::UNKNOWN; + out.hero = hero; out.hpos = hero->getPosition(false); if(!isInTheMap(out.hpos)/* || !gs->map->isInTheMap(dest)*/) //check input diff --git a/lib/CTownHandler.cpp b/lib/CTownHandler.cpp index 1439515a7..2ac384ceb 100644 --- a/lib/CTownHandler.cpp +++ b/lib/CTownHandler.cpp @@ -26,6 +26,12 @@ const int NAMES_PER_TOWN=16; // number of town names per faction in H3 files. Json can define any number +CBuilding::CBuilding(): + town(nullptr),mode(BUILD_NORMAL) +{ + +} + const std::string & CBuilding::Name() const { return name; @@ -64,6 +70,8 @@ si32 CBuilding::getDistance(BuildingID buildID) const CFaction::CFaction() { town = nullptr; + index = 0; + alignment = EAlignment::NEUTRAL; } CFaction::~CFaction() @@ -72,6 +80,7 @@ CFaction::~CFaction() } CTown::CTown() + : faction(nullptr), mageLevel(0), primaryRes(0), moatDamage(0), defaultTavernChance(0) { } diff --git a/lib/CTownHandler.h b/lib/CTownHandler.h index 7df2d78a6..32c10497f 100644 --- a/lib/CTownHandler.h +++ b/lib/CTownHandler.h @@ -56,6 +56,8 @@ public: BUILD_GRAIL // 3 - grail - building reqires grail to be built } mode; + CBuilding(); + const std::string &Name() const; const std::string &Description() const; diff --git a/lib/NetPacksBase.h b/lib/NetPacksBase.h index 2e64c5aa3..b2bb6e321 100644 --- a/lib/NetPacksBase.h +++ b/lib/NetPacksBase.h @@ -128,6 +128,7 @@ struct Component h & id & subtype & val & when; } Component() + :id(0), subtype(0), val(0), when(0) { } DLL_LINKAGE explicit Component(const CStackBasicDescriptor &stack); diff --git a/lib/NetPacksLib.cpp b/lib/NetPacksLib.cpp index 0be9b9be6..e304f8021 100644 --- a/lib/NetPacksLib.cpp +++ b/lib/NetPacksLib.cpp @@ -1688,6 +1688,7 @@ DLL_LINKAGE void ObstaclesRemoved::applyGs(CGameState *gs) DLL_LINKAGE CatapultAttack::CatapultAttack() { + attacker = -1; } DLL_LINKAGE CatapultAttack::~CatapultAttack() diff --git a/lib/VCMI_Lib.cpp b/lib/VCMI_Lib.cpp index ad965c54f..0d076f51c 100644 --- a/lib/VCMI_Lib.cpp +++ b/lib/VCMI_Lib.cpp @@ -125,8 +125,6 @@ void LibClasses::init() //FIXME: make sure that everything is ok after game restart //TODO: This should be done every time mod config changes - - IS_AI_ENABLED = false; } void LibClasses::clear() @@ -164,6 +162,7 @@ void LibClasses::makeNull() LibClasses::LibClasses() { + IS_AI_ENABLED = false; //init pointers to handlers makeNull(); } diff --git a/lib/VCMI_Lib.h b/lib/VCMI_Lib.h index 3cd5e60f6..b9ecbcf13 100644 --- a/lib/VCMI_Lib.h +++ b/lib/VCMI_Lib.h @@ -33,8 +33,8 @@ class DLL_LINKAGE LibClasses void callWhenDeserializing(); //should be called only by serialize !!! void makeNull(); //sets all handler pointers to null public: - bool IS_AI_ENABLED; //VLC is the only object visible from both CMT and GeniusAI - + bool IS_AI_ENABLED; //unused? + const IBonusTypeHandler * getBth() const; CArtHandler * arth; diff --git a/lib/mapObjects/CBank.cpp b/lib/mapObjects/CBank.cpp index 3c56ca4b8..12848d258 100644 --- a/lib/mapObjects/CBank.cpp +++ b/lib/mapObjects/CBank.cpp @@ -28,6 +28,8 @@ static std::string & visitedTxt(const bool visited) CBank::CBank() { + daycounter = 0; + resetDuration = 0; } CBank::~CBank() diff --git a/lib/mapObjects/CGPandoraBox.cpp b/lib/mapObjects/CGPandoraBox.cpp index eb7d5ed46..643d8d7a1 100644 --- a/lib/mapObjects/CGPandoraBox.cpp +++ b/lib/mapObjects/CGPandoraBox.cpp @@ -34,6 +34,13 @@ static void showInfoDialog(const CGHeroInstance* h, const ui32 txtID, const ui16 showInfoDialog(playerID,txtID,soundID); } +CGPandoraBox::CGPandoraBox() + : hasGuardians(false), gainedExp(0), manaDiff(0), moraleDiff(0), luckDiff(0) +{ + +} + + void CGPandoraBox::initObj(CRandomGenerator & rand) { blockVisit = (ID==Obj::PANDORAS_BOX); //block only if it's really pandora's box (events also derive from that class) @@ -362,6 +369,12 @@ void CGPandoraBox::afterSuccessfulVisit() const cb->removeAfterVisit(this); } +CGEvent::CGEvent() + : CGPandoraBox(), removeAfterVisit(false), availableFor(0), computerActivate(false), humanActivate(false) +{ + +} + void CGEvent::onHeroVisit( const CGHeroInstance * h ) const { if(!(availableFor & (1 << h->tempOwner.getNum()))) diff --git a/lib/mapObjects/CGPandoraBox.h b/lib/mapObjects/CGPandoraBox.h index dd851dac4..a38df2847 100644 --- a/lib/mapObjects/CGPandoraBox.h +++ b/lib/mapObjects/CGPandoraBox.h @@ -35,7 +35,7 @@ public: std::vector spells; //gained spells CCreatureSet creatures; //gained creatures - CGPandoraBox() : gainedExp(0), manaDiff(0), moraleDiff(0), luckDiff(0){}; + CGPandoraBox(); void initObj(CRandomGenerator & rand) override; void onHeroVisit(const CGHeroInstance * h) const override; void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const override; @@ -71,7 +71,7 @@ public: h & removeAfterVisit & availableFor & computerActivate & humanActivate; } - CGEvent() : CGPandoraBox(){}; + CGEvent(); void onHeroVisit(const CGHeroInstance * h) const override; private: void activated(const CGHeroInstance * h) const; diff --git a/lib/mapObjects/CObjectClassesHandler.cpp b/lib/mapObjects/CObjectClassesHandler.cpp index c35139170..bed66526e 100644 --- a/lib/mapObjects/CObjectClassesHandler.cpp +++ b/lib/mapObjects/CObjectClassesHandler.cpp @@ -357,6 +357,17 @@ std::string CObjectClassesHandler::getObjectHandlerName(si32 type) const return objects.at(type)->handlerName; } +AObjectTypeHandler::AObjectTypeHandler(): + type(-1), subtype(-1) +{ + +} + +AObjectTypeHandler::~AObjectTypeHandler() +{ + +} + void AObjectTypeHandler::setType(si32 type, si32 subtype) { this->type = type; diff --git a/lib/mapObjects/CObjectClassesHandler.h b/lib/mapObjects/CObjectClassesHandler.h index e65bb2ccf..86f589bdc 100644 --- a/lib/mapObjects/CObjectClassesHandler.h +++ b/lib/mapObjects/CObjectClassesHandler.h @@ -118,8 +118,8 @@ public: si32 type; si32 subtype; - - virtual ~AObjectTypeHandler(){} + AObjectTypeHandler(); + virtual ~AObjectTypeHandler(); void setType(si32 type, si32 subtype); void setTypeName(std::string type, std::string subtype); diff --git a/lib/mapObjects/CRewardableObject.cpp b/lib/mapObjects/CRewardableObject.cpp index efb5f4254..27e706bb5 100644 --- a/lib/mapObjects/CRewardableObject.cpp +++ b/lib/mapObjects/CRewardableObject.cpp @@ -454,6 +454,7 @@ void CRewardableObject::newTurn(CRandomGenerator & rand) const CRewardableObject::CRewardableObject(): soundID(soundBase::invalid), selectMode(0), + visitMode(0), selectedReward(0), resetDuration(0), canRefuse(false) diff --git a/lib/mapObjects/CommonConstructors.cpp b/lib/mapObjects/CommonConstructors.cpp index a0e029b46..4ead155b8 100644 --- a/lib/mapObjects/CommonConstructors.cpp +++ b/lib/mapObjects/CommonConstructors.cpp @@ -87,6 +87,7 @@ void CTownInstanceConstructor::configureObject(CGObjectInstance * object, CRando } CHeroInstanceConstructor::CHeroInstanceConstructor() + :heroClass(nullptr) { } @@ -257,7 +258,9 @@ std::vector CDwellingInstanceConstructor::getProducedCreature } CBankInstanceConstructor::CBankInstanceConstructor() + : bankResetDuration(0) { + } void CBankInstanceConstructor::initTypeData(const JsonNode & input)