From d7b7fb9dc88acfc66f25c6913240d9f496d32f88 Mon Sep 17 00:00:00 2001 From: Paul Kulchenko Date: Sat, 7 May 2022 14:37:42 -0700 Subject: [PATCH] Fix Fetch usage on urls without host before server gets an address --- tool/net/redbean.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tool/net/redbean.c b/tool/net/redbean.c index a96f27bf8..fff89c152 100644 --- a/tool/net/redbean.c +++ b/tool/net/redbean.c @@ -3805,10 +3805,11 @@ static int LuaFetch(lua_State *L) { port = usessl ? "443" : "80"; } } else { - ip = ntohl(servers.p[0].addr.sin_addr.s_addr); + 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", ntohs(servers.p[0].addr.sin_port))); + port = + gc(xasprintf("%d", servers.n ? ntohs(servers.p[0].addr.sin_port) : 80)); } if (!IsAcceptableHost(host, -1)) { luaL_argerror(L, 1, "invalid host");