[??-gdd7ec1fe4] Use after free in DoomRPG SE Titlemap

Bugs that have been investigated and resolved somehow.

Moderator: GZDoom Developers

Forum rules
Please don't bump threads here if you have a problem - it will often be forgotten about if you do. Instead, make a new thread here.
Post Reply
Edward-san
Posts: 1774
Joined: Sat Oct 17, 2009 9:40 am

[??-gdd7ec1fe4] Use after free in DoomRPG SE Titlemap

Post by Edward-san »

When I load GZDoom with Doom RPG SE (mod git hash df7af0dd) and leave the titlemap run, there's a certain moment when this happens (if the Address sanitizer is used):
Spoiler:
full backtrace:
Spoiler:
the ACS script call happens inside the ACS script "PissOffMarines" in DoomRPG/scripts/Outpost.c . I believe the specific call is this one, since it seems the only place where SetActorProperty with these parameters is called with the InTitle condition true.

Steps to reproduce:

Code: Select all

gzdoom -iwad DOOM2.WAD -file *path to DoomRPG*/DoomRPG
and let it go without doing anything.
User avatar
Zhs2
Posts: 1271
Joined: Fri Nov 07, 2008 3:29 pm
Graphics Processor: ATI/AMD with Vulkan/Metal Support
Location: Maryland, USA, but probably also in someone's mod somewhere
Contact:

Re: [??-gdd7ec1fe4] Use after free in DoomRPG SE Titlemap

Post by Zhs2 »

I've only seen the titlemap crash once with a VFE, never been able to reproduce it again. Glad to see someone found the reason why!
_mental_
 
 
Posts: 3812
Joined: Sun Aug 07, 2011 4:32 am

Re: [??-gdd7ec1fe4] Use after free in DoomRPG SE Titlemap

Post by _mental_ »

The crash is caused by a random spawner with TID assigned that doesn't spawn an actor. It boils down to a wrong order of function calls.
AActor::OnDestroy() which can remove actor from TID hash is called before setting a new TID which adds an actor to the given hash.

Objects with OF_EuthanizeMe flag set must not be added to TID hash in order to avoid dangling pointers in its linked lists.
This needs to be fixed in at least two places, for scripted spawning and for summon<...> CCMDs.

Although, the design with a writable public AActor::tid member and add/remove functions looks broken to me.
I think that TID should be changed by one function that handles corner cases like this one.
The right approach is ChangeTid() ZScript function.

There should no write access to TID outside of AActor class and things like AddToHash() should be private.
RemoveFromHash() function already exposed to ZScript should be deprecated.

I would like to know other opinions on this topic though.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49067
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: [??-gdd7ec1fe4] Use after free in DoomRPG SE Titlemap

Post by Graf Zahl »

Best implement it and let it be reviewed. Currently I cannot do anything about it.
_mental_
 
 
Posts: 3812
Joined: Sun Aug 07, 2011 4:32 am

Re: [??-gdd7ec1fe4] Use after free in DoomRPG SE Titlemap

Post by _mental_ »

Here is a minimum set of changes.

On the second though, almost the same can be achieved by adding check for OF_EuthanizeMe object flag to AActor::AddToHash().
It the flag is set, reset TID to zero and skip linking into the hash.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49067
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: [??-gdd7ec1fe4] Use after free in DoomRPG SE Titlemap

Post by Graf Zahl »

The 'second thought' should be done as the minimum. A destroyed actor should never be handled in there.

But if your PR makes using these functions unnecessary, all the better.
Post Reply

Return to “Closed Bugs [GZDoom]”