lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


It was thus said that the Great Ranier Vilela once stated:
> Em qua., 24 de fev. de 2021 às 23:17, Ranier Vilela <ranier.vf@gmail.com>
> escreveu:
> 
> > Em qua., 24 de fev. de 2021 às 22:54, Sean Conner <sean@conman.org>
> > escreveu:
> >
> >> > I have a bug reading an invalid pointer, in an adjacent library, which
> >> I'm
> >> > not sure is caused by Lua gc.
> >>
> >>   It may be an issue over who owns the memory for the userdata, but
> >> without
> >> knowing the exact error, it's hard to say.
> >>
> > Lua owns the pointer.
> > The code is run many times, then magically the "feeefeeefeeefeee" pointer
> > appears.
> > I need to make sure that there are no mistakes part of Lua C api.
> >
> Regarding the problem, I can already say with certainty that it is the case
> of:
> user-after-free
> https://stackoverflow.com/questions/2436020/detecting-use-after-free-on-windows-dangling-pointers

  I don't use Windows so I can't check this, but it sounds like the
following might be happening:

	* There is a userdata on the stack (either as a parameter to the C
	  based function, or via calling a Lua function from C).

	* You grab the pointer to the user data.

	* You cleanup the stack, thus removing the stack entry with the
	  userdata.

	* A GC is triggered and the userdata has no hard reference in the
	  Lua state, so the __gc() method is called.

	* The pointer is then used, thus triggering the issue.

  -spc (Just a thought ... )