guard against invalid ctrl entity handle resolutions when applying ctrl events; otherwise some edge cases can cause invalid writes.

This commit is contained in:
Ryan Fleury
2026-03-31 07:05:44 -07:00
parent 7021d6056a
commit d986ea6cd9
+14 -2
View File
@@ -1270,9 +1270,12 @@ ctrl_entity_store_apply_events(CTRL_EntityCtxRWStore *store, CTRL_EventList *lis
case CTRL_EventKind_NewProc:
{
CTRL_Entity *machine = ctrl_entity_from_handle(&store->ctx, ctrl_handle_make(event->entity.machine_id, dmn_handle_zero()));
if(machine != &ctrl_entity_nil)
{
CTRL_Entity *process = ctrl_entity_alloc(store, machine, CTRL_EntityKind_Process, event->arch, event->entity, (U64)event->entity_id);
process->tls_model = event->tls_model;
process->target_os = event->target_os;
}
}break;
case CTRL_EventKind_EndProc:
{
@@ -1294,6 +1297,8 @@ ctrl_entity_store_apply_events(CTRL_EntityCtxRWStore *store, CTRL_EventList *lis
case CTRL_EventKind_NewThread:
{
CTRL_Entity *process = ctrl_entity_from_handle(&store->ctx, event->parent);
if(process != &ctrl_entity_nil)
{
CTRL_Entity *thread = ctrl_entity_alloc(store, process, CTRL_EntityKind_Thread, event->arch, event->entity, (U64)event->entity_id);
CTRL_Entity *first_thread = ctrl_entity_child_from_kind(process, CTRL_EntityKind_Thread);
if(first_thread == thread)
@@ -1323,6 +1328,7 @@ ctrl_entity_store_apply_events(CTRL_EntityCtxRWStore *store, CTRL_EventList *lis
}
}
thread->stack_base = event->stack_base;
}
//ctrl_rip_from_thread(&store->ctx, event->entity);
}break;
case CTRL_EventKind_EndThread:
@@ -1346,7 +1352,7 @@ ctrl_entity_store_apply_events(CTRL_EntityCtxRWStore *store, CTRL_EventList *lis
{
ctrl_entity_equip_string(store, thread, event->string);
}
else
else if(process != &ctrl_entity_nil)
{
CTRL_Entity *pending_name = ctrl_entity_alloc(store, process, CTRL_EntityKind_PendingThreadName, Arch_Null, ctrl_handle_zero(), event->entity_id);
ctrl_entity_equip_string(store, pending_name, event->string);
@@ -1368,7 +1374,7 @@ ctrl_entity_store_apply_events(CTRL_EntityCtxRWStore *store, CTRL_EventList *lis
{
thread->rgba = event->rgba;
}
else
else if(process != &ctrl_entity_nil)
{
CTRL_Entity *pending = ctrl_entity_alloc(store, process, CTRL_EntityKind_PendingThreadColor, Arch_Null, ctrl_handle_zero(), event->entity_id);
pending->rgba = event->rgba;
@@ -1377,12 +1383,18 @@ ctrl_entity_store_apply_events(CTRL_EntityCtxRWStore *store, CTRL_EventList *lis
case CTRL_EventKind_ThreadFrozen:
{
CTRL_Entity *thread = ctrl_entity_from_handle(&store->ctx, event->entity);
if(thread != &ctrl_entity_nil)
{
thread->is_frozen = 1;
}
}break;
case CTRL_EventKind_ThreadThawed:
{
CTRL_Entity *thread = ctrl_entity_from_handle(&store->ctx, event->entity);
if(thread != &ctrl_entity_nil)
{
thread->is_frozen = 0;
}
}break;
//- rjf: modules