lua-users home
lua-l archive

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


Hi,

Marius Kjeldahl wrote:
> I've installed lua on my Linux Mandrake 7.2 [...]
>
> [marius@localhost test]$ lua -e 'dofile("luac.out")'
> Segmentation fault

Works perfectly well here (Linux/libc5).  But I think there's a bug in
Lua at that place (see below).

> open("luac.out", O_RDONLY)              = 3
> fstat64(3, 0xbffff1a4)                  = -1 ENOSYS (Function not
> implemented)
> fstat(3, {st_mode=S_IFREG|0644, st_size=3666, ...}) = 0
> old_mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40014000
> read(3, "\33Lua@\1\4\4\4 \6\t\10\22\346[\241\260\271\262A\n\0\0"...,
> 4096) = 3666
> close(3)                                = 0
> munmap(0x40014000, 4096)                = 0
> open("luac.out", O_RDONLY|O_LARGEFILE)  = 3
> --- SIGSEGV (Segmentation fault) ---
> +++ killed by SIGSEGV +++

I would blame the C library (it's glibc, isn't it ;-).  But check this
test program first (it does the same Lua does with the file).  Note that
the segfault happens even before the fread()...

----t.c----
#include <stdio.h>
int main(int argc, char **argv)
{
    char buf[256];
    FILE *f = fopen("luac.out", "r");  f||exit(1); fgetc(f);
    f = freopen("luac.out", "rb", f);  fread(buf, 1, 256, f);
    printf("ok!\n");  exit(0);
}
-----------

[Sidenote: IMHO it's pretty strange that glibc uses large file mode
on freopen especially as it should know from the former fstat64 that
it isn't supported on the system...]


About the bug: ldo.c:protectedparser _does_ calls the GC (early, just
before compilation/undumping).  So the assumption in ldo.c:parse_file
is wrong.

--- ldo.c       Wed Apr 11 02:09:10 2001
+++ ldo.c       Wed Apr 11 02:09:34 2001
@@ -275,9 +275,9 @@
   lua_pushstring(L, (filename == NULL) ? "(stdin)" : filename);
   lua_concat(L, 2);
   filename = lua_tostring(L, -1);  /* filename = '@'..filename */
-  lua_pop(L, 1);  /* OK: there is no GC during parser */
   luaZ_Fopen(&z, f, filename);
   status = protectedparser(L, &z, bin);
+  lua_pop(L, 1);  /* filename */
   if (f != stdin)
     fclose(f);
   return status;


But I doubt that this one is generating Marius' segfault...

Ciao, ET.