From 9a7cb399e5759c98d0a1177d574f1f2e12d69b34 Mon Sep 17 00:00:00 2001 From: Paul Kulchenko Date: Sun, 3 Jul 2022 12:39:41 -0700 Subject: [PATCH] Fix connecting to localhost when only IP address is specified in Fetch() --- tool/net/redbean.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tool/net/redbean.c b/tool/net/redbean.c index 097b4fbbc..7a4f71769 100644 --- a/tool/net/redbean.c +++ b/tool/net/redbean.c @@ -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");