fix(gta-core-five): validate pool entry in target scoring function#3816
fix(gta-core-five): validate pool entry in target scoring function#3816st860923 wants to merge 1 commit intocitizenfx:masterfrom
Conversation
|
I have a few questions with this PR and the supposed fix
|
Thanks for the review.
Also for the exit path, the MOVAPS before the SUBPS is 7 bytes (0F 28 8B ? ? ? ?), so wouldn't the exit label be at pattern match - 7 instead of - 8? Just want to make sure. |
Yes
Yeah I miscounted the total number of instructions, 7 is correct (ends up at the start of the movaps instruction, otherwise you can always generate/craft a pattern for that movaps instruction). |
5b3c6dd to
0bcdf60
Compare
Goal of this PR
Prevent a client crash caused by a null pointer dereference in a scoring function that evaluates entities as potential targets. The function takes two entity pointers, switches on the entity type byte at +0x28 (handling types 3, 4, and 5), and accumulates a float score in XMM9 by multiplying various weight factors based on distance, flags, and task state. Its caller iterates up to 32 entities, collects scores, and performs a weighted random selection to pick a target.
In the type-4 branch, the function searches a linked list for a node matching a specific type, then uses the returned index to look up an entry from a pool. The pool lookup can return NULL when the slot has been freed (stale index), but the code dereferences the result at offset +0xDC without a null check, causing the crash.
How is this PR achieving the goal
Replaces the CALL to the pool lookup function at the specific crash site with a safe wrapper. When the pool lookup returns NULL, the wrapper returns a pointer to a static zeroed buffer instead, allowing the subsequent read at +0xDC to safely return 0. This causes the code to fall through the switch-case harmlessly and exit normally. Only the single call site inside the scoring function is patched — the pool lookup has 70 other callers which remain unaffected.
This PR applies to the following area(s)
FiveM
Successfully tested on
Game builds: 3258
Platforms: Windows
Checklist
Fixes issues