fix crash in particle and model server from attempting to edit items that dont exist in the server

This commit is contained in:
ZappoMan 2014-07-11 11:29:32 -07:00
parent dbca97c71b
commit 4c3a1d192e
2 changed files with 14 additions and 12 deletions

View file

@ -331,6 +331,7 @@ ModelItem ModelItem::fromEditPacket(const unsigned char* data, int length, int&
newModelItem.setCreatorTokenID(creatorTokenID); newModelItem.setCreatorTokenID(creatorTokenID);
newModelItem._newlyCreated = true; newModelItem._newlyCreated = true;
valid = true;
} else { } else {
// look up the existing modelItem // look up the existing modelItem
@ -339,20 +340,19 @@ ModelItem ModelItem::fromEditPacket(const unsigned char* data, int length, int&
// copy existing properties before over-writing with new properties // copy existing properties before over-writing with new properties
if (existingModelItem) { if (existingModelItem) {
newModelItem = *existingModelItem; newModelItem = *existingModelItem;
valid = true;
} else { } else {
// the user attempted to edit a modelItem that doesn't exist // the user attempted to edit a modelItem that doesn't exist
qDebug() << "user attempted to edit a modelItem that doesn't exist..."; qDebug() << "user attempted to edit a modelItem that doesn't exist... editID=" << editID;
// NOTE: even though this is a bad editID, we have to consume the edit details, so that
// the buffer doesn't get corrupted for further processing...
valid = false; valid = false;
return newModelItem;
} }
newModelItem._id = editID; newModelItem._id = editID;
newModelItem._newlyCreated = false; newModelItem._newlyCreated = false;
} }
// if we got this far, then our result will be valid
valid = true;
// lastEdited // lastEdited
memcpy(&newModelItem._lastEdited, dataAt, sizeof(newModelItem._lastEdited)); memcpy(&newModelItem._lastEdited, dataAt, sizeof(newModelItem._lastEdited));
dataAt += sizeof(newModelItem._lastEdited); dataAt += sizeof(newModelItem._lastEdited);

View file

@ -385,6 +385,8 @@ Particle Particle::fromEditPacket(const unsigned char* data, int length, int& pr
newParticle._newlyCreated = true; newParticle._newlyCreated = true;
newParticle.setAge(0); // this guy is new! newParticle.setAge(0); // this guy is new!
valid = true;
} else { } else {
// look up the existing particle // look up the existing particle
const Particle* existingParticle = tree->findParticleByID(editID, true); const Particle* existingParticle = tree->findParticleByID(editID, true);
@ -392,20 +394,20 @@ Particle Particle::fromEditPacket(const unsigned char* data, int length, int& pr
// copy existing properties before over-writing with new properties // copy existing properties before over-writing with new properties
if (existingParticle) { if (existingParticle) {
newParticle = *existingParticle; newParticle = *existingParticle;
valid = true;
} else { } else {
// the user attempted to edit a particle that doesn't exist // the user attempted to edit a particle that doesn't exist
qDebug() << "user attempted to edit a particle that doesn't exist..."; qDebug() << "user attempted to edit a particle that doesn't exist... editID=" << editID;
// NOTE: even though this is a bad particle ID, we have to consume the edit details, so that
// the buffer doesn't get corrupted for further processing...
valid = false; valid = false;
return newParticle;
} }
newParticle._id = editID; newParticle._id = editID;
newParticle._newlyCreated = false; newParticle._newlyCreated = false;
} }
// if we got this far, then our result will be valid
valid = true;
// lastEdited // lastEdited
memcpy(&newParticle._lastEdited, dataAt, sizeof(newParticle._lastEdited)); memcpy(&newParticle._lastEdited, dataAt, sizeof(newParticle._lastEdited));
dataAt += sizeof(newParticle._lastEdited); dataAt += sizeof(newParticle._lastEdited);