[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: luasocket: segfault with dns.toip and suggested fix
- From: William Trenker <wtrenker@...>
- Date: Thu, 2 Jun 2005 11:12:18 -0700
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