lua-users home
lua-l archive

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


I think the root problem is that this C expression (f==stdin) cannot
be expected to do anything useful.

The fix to luaL_loadfile is simple (I posted a patch yesterday).

The only other place in the Lua code which attempts to compare a FILE*
to stdin (or any standard stream) is io_gc() in liolib.c.  This bug
could leave a stream open, assuming the C implementation reuses FILE
slots:

lua_open(L); luaL_openlibs(L);
lua_dostring(L, " io.stdin:close(); io.open'foo'; ");
lua_close(L);
/* oops, file foo is still open and its FILE* handle is leaked */

The fix is to mark the three standard stream userdata when they are
created and then check for this mark in io_gc().  I have a patch, but
it's a work in progress as I am attempting to solve a whole slew of
problems:

calling fopen() with an invalid mode string
illegal file operations (flushing input stream, illegal seeks, etc)
illegal file operation sequences (reading an update stream after
writing without seeking, etc)

    -Mark