lua-users home
lua-l archive

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

On 2018-04-16 01:49 PM, Viacheslav Usov wrote:
On Mon, Apr 16, 2018 at 6:04 PM, Roberto Ierusalimschy < <>> wrote:

> Practically all functions in the Lua-C API can crash, when called with invalid arguments.

In the referenced thread, the C-language arguments given to the function were not invalid. It was the content of the Lua stack that was problematic for that function.

As far as the Lua C API is concerned, stack values are function arguments. How else would you pass tables to functions? They don't exist outside the Lua state.

In the "checking for safety" context, that means the stack's content should be validated, if it is accepted from another party.

> I believe this happens with most C libraries.

No, not really. It is one thing if a parameter in a C function is a pointer, then the argument simply has to point to a valid memory location. It is quite another when it is a kind of a "handle", then it is rather typical for a function to return an error result if the argument has an invalid or unsuitable value. See POSIX/read(), for example. Lua's stack indices look more like handles than pointers to me, but that, of course, can be just me.


Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.