lua-users home
lua-l archive

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


I'm porting lua / luasocket to a mipsel processor running Linux 2.4.20
with uclibc.  I've pretty much got it done but I see that dns.toip
segfaults.

Some study on the web indicates that uclibc handles gethostbyname a
bit strangely.  On most Linux systems glibc, per the specifications,
sets the alias field in the hostent struct as a pointer to a
null-terminated list of pointers to alias names for the given
hostname.  Unfortunately uclibc sets the hostent.alias value to a
NULL.  This causes inet.c in the luasocket package to dereference a
null pointer which, in turn, appears to cause a page fault.  The code,
in inet.c at line 175, is here:
    while (*alias) {            //page fault when alias is NULL
    lua_pushnumber(L, i);
    lua_pushstring(L, *alias);
    lua_settable(L, -3);
    i++; alias++;
    }

As a fix I've simply put a test around the above code like this:
    if (alias) {     //WTrenker - uclibc returns NULL instead of pointer to NULL
        while (*alias) {
        lua_pushnumber(L, i);
        lua_pushstring(L, *alias);
        lua_settable(L, -3);
        i++; alias++;
        }
    }

The above fix works but I'm not sure if it is the best solution within
the design of luasocket; perhaps a fix deeper in the socket hierarchy
(e.g. usocket.c) would be better.

Let me know if I'm off-track here.

Thanks,
Bill Trenker
Kelowna BC Canada