#Stack based UAF

23 messages · Page 1 of 1 (latest)

jolly briar
#

Does anyone know why this happens and how I can fix this stack UAF?:

Object B constructs
Object A constructs and creates something on Object B
...
Object B gets destroyed on shutdown
Object A attempts to release what it allocated on Object B... BOOM

This is unusal since Object B is constructed first.

mossy compassBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

heady mirage
#

shared_ptr 😄

jolly briar
jolly briar
heady mirage
#

heritance ?

fast jetty
#

so maybe you could try this #cpp-help-text message

#

mostly to figure out if that is indeed the problem

#

because normally, if the local variable engine gets constructed after the local variable physicsEngine, then it should get destroyed first

jolly briar
fast jetty
#

how so?

jolly briar
#

the entire update loop and rendering expects engine to be present

fast jetty
#

ah, but couldn't you move that into this new function too?

jolly briar
#

i'll try that them

#

*then

fast jetty
#

like, all I wanted to do was to make sure that engine gets destructed before physicsEngine, such that you can clearly see in a debugger when each step happens

jolly briar
#

Oh wait, know I know what you mean, I just put the engine creation and loop in a scope

fast jetty
#

yeah

jolly briar
# fast jetty yeah

I added that it still crashed, I noticed null checks were missing, I added those and now it works without scope. But for anyone trying to read this in the future. The scope can work to fix this.

fast jetty
#

but so the problem wasn't actually related to scoped or order of destruction, but to missing null checks?

jolly briar
#

yeah. but the debugger decided to not show me that.

fast jetty
#

yeah I figured

jolly briar
#

but after scope, it showed me everything