From ebcf82c9f3e5668e2b0218712bba64ec3287d6be Mon Sep 17 00:00:00 2001 From: TJ Saunders Date: Sat, 18 Jul 2020 12:15:17 -0700 Subject: [PATCH] Issue #158: When ignoring RFC1918 addresses, make sure we properly set the remote port in the replacement address. --- mod_proxy.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/mod_proxy.c b/mod_proxy.c index 683a518..ba540b5 100644 --- a/mod_proxy.c +++ b/mod_proxy.c @@ -2683,6 +2683,12 @@ MODRET proxy_eprt(cmd_rec *cmd, struct proxy_session *proxy_sess) { rfc1918_ipstr = pr_netaddr_get_ipstr(remote_addr); remote_addr = pr_netaddr_dup(session.pool, session.c->remote_addr); + + /* Make sure the remote port is set on our duplicated netaddr, too + * (Issue #158). + */ + pr_netaddr_set_port2(remote_addr, remote_port); + (void) pr_log_writefile(proxy_logfd, MOD_PROXY_VERSION, "client sent RFC1918 address '%s' in EPRT command, ignoring it and " "using '%s'", rfc1918_ipstr, pr_netaddr_get_ipstr(remote_addr)); @@ -3113,6 +3119,12 @@ MODRET proxy_port(cmd_rec *cmd, struct proxy_session *proxy_sess) { rfc1918_ipstr = pr_netaddr_get_ipstr(remote_addr); remote_addr = pr_netaddr_dup(session.pool, session.c->remote_addr); + + /* Make sure the remote port is set on our duplicated netaddr, too + * (Issue #158). + */ + pr_netaddr_set_port2(remote_addr, remote_port); + (void) pr_log_writefile(proxy_logfd, MOD_PROXY_VERSION, "client sent RFC1918 address '%s' in PORT command, ignoring it and " "using '%s'", rfc1918_ipstr, pr_netaddr_get_ipstr(remote_addr));