Skip to content

Commit

Permalink
21035: Fixes potential crash when calling union, mix, or difference_e…
Browse files Browse the repository at this point in the history
…ntities opcodes (#197)
  • Loading branch information
howsohazard authored Jul 25, 2024
1 parent 7ea8c91 commit 7335470
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
7 changes: 3 additions & 4 deletions src/Amalgam/entity/EntityManipulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,13 +357,12 @@ EvaluableNodeReference EntityManipulation::DifferenceEntities(Interpreter *inter
a_code = entity_from_a->second->GetRoot(enm);

EvaluableNode *b_code = entity_to_create->GetRoot(enm);
EvaluableNode *entity_difference = EvaluableNodeTreeDifference::DifferenceTrees(enm, a_code, b_code);

//if either entity needs a cycle check, then everything will need to be checked for cycles later
if( (a_code != nullptr && a_code->GetNeedCycleCheck())
|| (b_code != nullptr && b_code->GetNeedCycleCheck()) )
EvaluableNodeManager::UpdateFlagsForNodeTree(entity_difference);
if(entity_difference != nullptr && entity_difference->GetNeedCycleCheck())
cycle_free = false;

EvaluableNode *entity_difference = EvaluableNodeTreeDifference::DifferenceTrees(enm, a_code, b_code);
call_lambda->AppendOrderedChildNode(entity_difference);

EvaluableNode *call_assoc = enm->AllocNode(ENT_ASSOC);
Expand Down
2 changes: 2 additions & 0 deletions src/Amalgam/evaluablenode/EvaluableNodeTreeManipulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -501,10 +501,12 @@ class EvaluableNodeTreeManipulation

//Returns a tree that consists of only nodes that are common across all of the trees specified,
// where all returned values are newly allocated and modifiable
//Note that MergeTrees does not guarantee that EvaluableNodeFlags will be set appropriately
static EvaluableNode *MergeTrees(NodesMergeMethod *mm, EvaluableNode *tree1, EvaluableNode *tree2);

//Returns a tree that is a copy of tree but mutated based on mutation_rate
// will create the new tree with interpreter's evaluableNodeManager and will use interpreter's RandomStream
//Note that MutateTree does not guarantee that EvaluableNodeFlags will be set appropriately
static EvaluableNode *MutateTree(Interpreter *interpreter, EvaluableNodeManager *enm, EvaluableNode *tree, double mutation_rate, CompactHashMap<StringInternPool::StringID, double> *mutation_weights, CompactHashMap<EvaluableNodeType, double> *evaluable_node_weights);

//traverses tree and replaces any string that matches a key of to_replace with the value in to_replace
Expand Down
9 changes: 3 additions & 6 deletions src/Amalgam/interpreter/InterpreterOpcodesCodeMixing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,7 @@ EvaluableNodeReference Interpreter::InterpretNode_ENT_INTERSECT(EvaluableNode *e

EvaluableNode *result = EvaluableNodeTreeManipulation::IntersectTrees(evaluableNodeManager, n1, n2);

if(n1.GetNeedCycleCheck() || n2.GetNeedCycleCheck())
EvaluableNodeManager::UpdateFlagsForNodeTree(result);
EvaluableNodeManager::UpdateFlagsForNodeTree(result);
return EvaluableNodeReference(result, true);
}

Expand All @@ -180,8 +179,7 @@ EvaluableNodeReference Interpreter::InterpretNode_ENT_UNION(EvaluableNode *en, b

EvaluableNode *result = EvaluableNodeTreeManipulation::UnionTrees(evaluableNodeManager, n1, n2);

if(n1.GetNeedCycleCheck() || n2.GetNeedCycleCheck())
EvaluableNodeManager::UpdateFlagsForNodeTree(result);
EvaluableNodeManager::UpdateFlagsForNodeTree(result);
return EvaluableNodeReference(result, true);
}

Expand Down Expand Up @@ -255,8 +253,7 @@ EvaluableNodeReference Interpreter::InterpretNode_ENT_MIX(EvaluableNode *en, boo
EvaluableNode *result = EvaluableNodeTreeManipulation::MixTrees(randomStream.CreateOtherStreamViaRand(),
evaluableNodeManager, n1, n2, blend1, blend2, similar_mix_chance);

if(n1.GetNeedCycleCheck() || n2.GetNeedCycleCheck())
EvaluableNodeManager::UpdateFlagsForNodeTree(result);
EvaluableNodeManager::UpdateFlagsForNodeTree(result);
return EvaluableNodeReference(result, true);
}

Expand Down
1 change: 1 addition & 0 deletions src/Amalgam/interpreter/InterpreterOpcodesEntityAccess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ EvaluableNodeReference Interpreter::InterpretNode_ENT_CONTAINED_ENTITIES_and_COM
//if not a valid query, return nullptr
if(conditionsBuffer.size() == 0)
{
evaluableNodeManager->FreeNodeTreeIfPossible(entity_id_path);
evaluableNodeManager->FreeNodeTreeIfPossible(query_params);
return EvaluableNodeReference::Null();
}
Expand Down

0 comments on commit 7335470

Please sign in to comment.