Skip to content

Commit a71925e

Browse files
committed
增强一些地方的安全性问题
1 parent 9f6df34 commit a71925e

6 files changed

Lines changed: 49 additions & 28 deletions

File tree

‎kbe/src/lib/entitydef/entity_macro.hpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,8 +611,8 @@ public: \
611611
{ \
612612
isDestroyed_ = true; \
613613
onDestroy(); \
614+
Py_DECREF(this); \
614615
} \
615-
Py_DECREF(this); \
616616
} \
617617
INLINE bool isDestroyed()const \
618618
{ \

‎kbe/src/server/baseapp/base.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ void Base::onDestroyEntity(bool deleteFromDB, bool writeToDB)
443443

444444
if(dbmgrinfos == NULL || dbmgrinfos->pChannel == NULL || dbmgrinfos->cid == 0)
445445
{
446-
ERROR_MSG("Base::onCellWriteToDBCompleted: not found dbmgr!\n");
446+
ERROR_MSG(boost::format("Base::onDestroyEntity(%1%): writeToDB not found dbmgr!\n") % this->getID());
447447
return;
448448
}
449449

@@ -868,7 +868,7 @@ void Base::onCellWriteToDBCompleted(CALLBACK_ID callbackID)
868868

869869
if(dbmgrinfos == NULL || dbmgrinfos->pChannel == NULL || dbmgrinfos->cid == 0)
870870
{
871-
ERROR_MSG("Base::onCellWriteToDBCompleted: not found dbmgr!\n");
871+
ERROR_MSG(boost::format("Base::onCellWriteToDBCompleted(%1%): not found dbmgr!\n") % this->getID());
872872
return;
873873
}
874874

‎kbe/src/server/baseapp/baseapp.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ void Baseapp::onCellAppDeath(Mercury::Channel * pChannel)
521521
SCRIPT_ERROR_CHECK();
522522

523523

524-
RestoreEntityHandler* pRestoreEntityHandler = new RestoreEntityHandler(this->getNetworkInterface());
524+
RestoreEntityHandler* pRestoreEntityHandler = new RestoreEntityHandler(pChannel->componentID(), this->getNetworkInterface());
525525
Entities<Base>::ENTITYS_MAP& entitiesMap = pEntities_->getEntities();
526526
Entities<Base>::ENTITYS_MAP::const_iterator iter = entitiesMap.begin();
527527
while (iter != entitiesMap.end())

‎kbe/src/server/baseapp/restore_entity_handler.cpp‎

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,17 @@ along with KBEngine. If not, see <http://www.gnu.org/licenses/>.
3131
namespace KBEngine{
3232

3333
//-------------------------------------------------------------------------------------
34-
RestoreEntityHandler::RestoreEntityHandler(Mercury::NetworkInterface & networkInterface):
34+
RestoreEntityHandler::RestoreEntityHandler(COMPONENT_ID cellappID, Mercury::NetworkInterface & networkInterface):
3535
Task(),
3636
networkInterface_(networkInterface),
3737
entities_(),
3838
inProcess_(false),
3939
restoreSpaces_(),
40+
otherRestoredSpaces_(),
4041
broadcastOtherBaseapps_(false),
4142
tickReport_(0),
42-
spaceIDs_()
43+
spaceIDs_(),
44+
cellappID_(cellappID)
4345
{
4446
// networkInterface_.mainDispatcher().addFrequentTask(this);
4547
}
@@ -50,8 +52,8 @@ RestoreEntityHandler::~RestoreEntityHandler()
5052
if(inProcess_)
5153
networkInterface_.mainDispatcher().cancelFrequentTask(this);
5254

53-
std::vector<RestoreData>::iterator restoreSpacesIter = ohterRestoredSpaces_.begin();
54-
for(; restoreSpacesIter != ohterRestoredSpaces_.end(); restoreSpacesIter++)
55+
std::vector<RestoreData>::iterator restoreSpacesIter = otherRestoredSpaces_.begin();
56+
for(; restoreSpacesIter != otherRestoredSpaces_.end(); restoreSpacesIter++)
5557
{
5658
if((*restoreSpacesIter).cell)
5759
{
@@ -60,7 +62,7 @@ RestoreEntityHandler::~RestoreEntityHandler()
6062
}
6163
}
6264

63-
DEBUG_MSG("RestoreEntityHandler::~RestoreEntityHandler()\n");
65+
DEBUG_MSG(boost::format("RestoreEntityHandler::~RestoreEntityHandler(%1%)\n") % cellappID_);
6466
}
6567

6668
//-------------------------------------------------------------------------------------
@@ -131,8 +133,8 @@ bool RestoreEntityHandler::process()
131133
if(timestamp() - tickReport_ > uint64( 3 * stampsPerSecond() ))
132134
{
133135
tickReport_ = timestamp();
134-
INFO_MSG(boost::format("RestoreEntityHandler::process(): wait for localSpace to get cell!, entitiesSize(%1%), spaceSize=%2%\n") %
135-
entities_.size() % restoreSpaces_.size());
136+
INFO_MSG(boost::format("RestoreEntityHandler::process(%3%): wait for localSpace to get cell!, entitiesSize(%1%), spaceSize=%2%\n") %
137+
entities_.size() % restoreSpaces_.size() % cellappID_);
136138
}
137139

138140
int spaceCellCount = 0;
@@ -174,7 +176,7 @@ bool RestoreEntityHandler::process()
174176
}
175177
else
176178
{
177-
ERROR_MSG(boost::format("RestoreEntityHandler::process(): lose space(%1%).\n") % (*restoreSpacesIter).id);
179+
ERROR_MSG(boost::format("RestoreEntityHandler::process(%1%): lose space(%2%).\n") % cellappID_ % (*restoreSpacesIter).id);
178180
}
179181
}
180182

@@ -186,7 +188,7 @@ bool RestoreEntityHandler::process()
186188
{
187189
broadcastOtherBaseapps_ = true;
188190

189-
INFO_MSG("RestoreEntityHandler::process(): begin broadcast-spaceGetCell to otherBaseapps...\n");
191+
INFO_MSG(boost::format("RestoreEntityHandler::process(%1%): begin broadcast-spaceGetCell to otherBaseapps...\n") % cellappID_);
190192

191193
std::vector<RestoreData>::iterator restoreSpacesIter = restoreSpaces_.begin();
192194
for(; restoreSpacesIter != restoreSpaces_.end(); restoreSpacesIter++)
@@ -216,8 +218,8 @@ bool RestoreEntityHandler::process()
216218

217219
if(pChannel)
218220
{
219-
INFO_MSG(boost::format("RestoreEntityHandler::process(): broadcast baseapp[%1%, %2%], spaceID[%3%], utype[%4%]...\n") %
220-
(*comsiter).cid % pChannel->c_str() % spaceID % utype);
221+
INFO_MSG(boost::format("RestoreEntityHandler::process(%5%): broadcast baseapp[%1%, %2%], spaceID[%3%], utype[%4%]...\n") %
222+
(*comsiter).cid % pChannel->c_str() % spaceID % utype % cellappID_);
221223

222224
Mercury::Bundle* pBundle = Mercury::Bundle::ObjPool().createObject();
223225
(*pBundle).newMessage(BaseappInterface::onRestoreSpaceCellFromOtherBaseapp);
@@ -235,8 +237,8 @@ bool RestoreEntityHandler::process()
235237
if(timestamp() - tickReport_ > uint64( 3 * stampsPerSecond() ))
236238
{
237239
tickReport_ = timestamp();
238-
INFO_MSG(boost::format("RestoreEntityHandler::process(): wait for otherBaseappSpaces to get cell!, entitiesSize(%1%), spaceSize=%2%\n") %
239-
entities_.size() % spaceIDs_.size());
240+
INFO_MSG(boost::format("RestoreEntityHandler::process(%1%): wait for otherBaseappSpaces to get cell!, entitiesSize(%2%), spaceSize=%3%\n") %
241+
cellappID_ % entities_.size() % spaceIDs_.size());
240242
}
241243

242244
return true;
@@ -286,8 +288,8 @@ bool RestoreEntityHandler::process()
286288

287289
if(cellMailbox == NULL)
288290
{
289-
restoreSpacesIter = ohterRestoredSpaces_.begin();
290-
for(; restoreSpacesIter != ohterRestoredSpaces_.end(); restoreSpacesIter++)
291+
restoreSpacesIter = otherRestoredSpaces_.begin();
292+
for(; restoreSpacesIter != otherRestoredSpaces_.end(); restoreSpacesIter++)
291293
{
292294
if(pBase->getSpaceID() == (*restoreSpacesIter).spaceID && (*restoreSpacesIter).cell)
293295
{
@@ -303,8 +305,15 @@ bool RestoreEntityHandler::process()
303305
}
304306
else
305307
{
308+
ENTITY_ID delID = pBase->getID();
309+
306310
pBase->destroy();
307-
iter = entities_.erase(iter);
311+
WARNING_MSG(boost::format("RestoreEntityHandler::process(%1%): not fount spaceCell, killed base(%2%)!")
312+
% cellappID_ % delID);
313+
314+
if(Baseapp::getSingleton().findEntity(delID) == NULL)
315+
iter = entities_.erase(iter);
316+
308317
continue;
309318
}
310319
}
@@ -320,8 +329,8 @@ bool RestoreEntityHandler::process()
320329

321330
if(entities_.size() == 0)
322331
{
323-
std::vector<RestoreData>::iterator restoreSpacesIter = ohterRestoredSpaces_.begin();
324-
for(; restoreSpacesIter != ohterRestoredSpaces_.end(); restoreSpacesIter++)
332+
std::vector<RestoreData>::iterator restoreSpacesIter = otherRestoredSpaces_.begin();
333+
for(; restoreSpacesIter != otherRestoredSpaces_.end(); restoreSpacesIter++)
325334
{
326335
if((*restoreSpacesIter).cell)
327336
{
@@ -330,7 +339,7 @@ bool RestoreEntityHandler::process()
330339
}
331340
}
332341

333-
ohterRestoredSpaces_.clear();
342+
otherRestoredSpaces_.clear();
334343

335344
inProcess_ = false;
336345
Baseapp::getSingleton().onRestoreEntitiesOver(this);
@@ -344,7 +353,10 @@ bool RestoreEntityHandler::process()
344353
void RestoreEntityHandler::onRestoreSpaceCellFromOtherBaseapp(COMPONENT_ID baseappID, COMPONENT_ID cellappID,
345354
SPACE_ID spaceID, ENTITY_ID spaceEntityID, ENTITY_SCRIPT_UID utype, bool destroyed)
346355
{
356+
SIZE_T oldsize = spaceIDs_.size();
347357
spaceIDs_.erase(std::remove(spaceIDs_.begin(), spaceIDs_.end(), spaceID), spaceIDs_.end());
358+
if(oldsize == spaceIDs_.size())
359+
return;
348360

349361
RestoreData data;
350362
data.id = spaceEntityID;
@@ -358,7 +370,7 @@ void RestoreEntityHandler::onRestoreSpaceCellFromOtherBaseapp(COMPONENT_ID basea
358370
ScriptDefModule* sm = EntityDef::findScriptModule(utype);
359371
if(sm == NULL)
360372
{
361-
ERROR_MSG(boost::format("RestoreEntityHandler::onRestoreSpaceCellFromOtherBaseapp: not found utype %1%!\n") % utype);
373+
ERROR_MSG(boost::format("RestoreEntityHandler::onRestoreSpaceCellFromOtherBaseapp(%1%): not found utype %2%!\n") % cellappID_ % utype);
362374
}
363375
else
364376
{
@@ -367,7 +379,7 @@ void RestoreEntityHandler::onRestoreSpaceCellFromOtherBaseapp(COMPONENT_ID basea
367379
}
368380
}
369381

370-
ohterRestoredSpaces_.push_back(data);
382+
otherRestoredSpaces_.push_back(data);
371383
}
372384

373385
//-------------------------------------------------------------------------------------

‎kbe/src/server/baseapp/restore_entity_handler.hpp‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class RestoreEntityHandler : public Task
4141
};
4242

4343
public:
44-
RestoreEntityHandler(Mercury::NetworkInterface & networkInterface);
44+
RestoreEntityHandler(COMPONENT_ID cellappID, Mercury::NetworkInterface & networkInterface);
4545
~RestoreEntityHandler();
4646

4747
bool process();
@@ -59,14 +59,16 @@ class RestoreEntityHandler : public Task
5959
bool inProcess_;
6060

6161
std::vector<RestoreData> restoreSpaces_;
62-
std::vector<RestoreData> ohterRestoredSpaces_;
62+
std::vector<RestoreData> otherRestoredSpaces_;
6363

6464
// space创建好cell后广播给其他baseapp
6565
bool broadcastOtherBaseapps_;
6666

6767
uint64 tickReport_;
6868

6969
std::vector<SPACE_ID> spaceIDs_;
70+
71+
COMPONENT_ID cellappID_;
7072
};
7173

7274

‎kbe/src/server/baseappmgr/baseappmgr.cpp‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ void Baseappmgr::registerPendingAccountToBaseappAddr(Mercury::Channel* pChannel,
274274
Components::ComponentInfos* cinfos = Components::getSingleton().findComponent(componentID);
275275
if(cinfos == NULL || cinfos->pChannel == NULL)
276276
{
277+
ERROR_MSG(boost::format("Baseappmgr::onPendingAccountGetBaseappAddr: not found baseapp(%1%).") % componentID);
277278
return;
278279
}
279280

@@ -290,7 +291,13 @@ void Baseappmgr::onPendingAccountGetBaseappAddr(Mercury::Channel* pChannel,
290291
{
291292
Components::COMPONENTS& components = Components::getSingleton().getComponents(LOGINAPP_TYPE);
292293
size_t componentSize = components.size();
293-
KBE_ASSERT(componentSize > 0);
294+
295+
if(componentSize == 0)
296+
{
297+
ERROR_MSG("Baseappmgr::onPendingAccountGetBaseappAddr: not found loginapp.");
298+
return;
299+
}
300+
294301
Components::COMPONENTS::iterator iter = components.begin();
295302
Mercury::Channel* lpChannel = (*iter).pChannel;
296303

0 commit comments

Comments
 (0)