Fix connecting to localhost when only IP address is specified in Fetch()

This commit is contained in:
Paul Kulchenko 2022-07-03 12:39:41 -07:00
parent 14fd395f03
commit 9a7cb399e5

View file

@ -3819,12 +3819,11 @@ static int LuaFetch(lua_State *L) {
} else {
port = "80";
}
} else if ((ip = ParseIp(urlarg, -1)) != -1) {
host = urlarg;
port = "80";
} else {
ip = servers.n ? ntohl(servers.p[0].addr.sin_addr.s_addr) : INADDR_LOOPBACK;
host =
gc(xasprintf("%hhu.%hhu.%hhu.%hhu", ip >> 24, ip >> 16, ip >> 8, ip));
port =
gc(xasprintf("%d", servers.n ? ntohs(servers.p[0].addr.sin_port) : 80));
return LuaNilError(L, "invalid host");
}
if (!IsAcceptableHost(host, -1)) {
return LuaNilError(L, "invalid host");