lua-users home
lua-l archive

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


On Mon, Nov 22, 2021 at 1:19 PM Meir Shpilraien <meir@redis.com> wrote:

> I see Lua is defining a global called EXTRA_STACK which is set to 5. I also see that Lua always allocated EXTRA_STACK more elements than the actual stack size. My question, assuming my code violates the C API and uses these 5 extra elements (I don't really want to do it but wonder what will happen if something will use it because of a bug for example). Am I risking any crashes or invalid memory write/read. Valgrind do not warn about it of course, but I wonder if Lua might try to use this memory at some point and will not found what it is assuming to find there (because it was overwritten)

Lua assumes that it always has some available stack slots through this
mechanism. It expects that any C code using the stack will use the
stack within the safely defined minimal size, or will call
lua_checkstack(). In some scenarios Lua will push elements onto the
stack without checking and growing the stack, relying specifically on
the EXTRA_STACK assumption. When the stack overflows, typical C
"undefined behavior" ensues, which can range from benign to
catastrophic.

Cheers,
V.