From d058fd3f3611047a985a7751f58b15c3d0e67c75 Mon Sep 17 00:00:00 2001 From: Markus Stenberg Date: Sat, 3 May 2014 08:54:13 +0300 Subject: [PATCH] miniupnpd/pcpserver.c: Added checks for third-party allowed for it to be used. If allowed, checking it against source address, with inverse logic from that of non-thirdparty case. --- miniupnpd/pcpserver.c | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/miniupnpd/pcpserver.c b/miniupnpd/pcpserver.c index baba945..cfcafb5 100644 --- a/miniupnpd/pcpserver.c +++ b/miniupnpd/pcpserver.c @@ -1049,13 +1049,29 @@ static int ValidatePCPMsg(pcp_info_t *pcp_msg_info) return 0; } - /* RFC 6887, section 8.2: MUST return address mismatch if NAT - * in middle. (XXX n/a in thirdparty case) */ - if (memcmp(pcp_msg_info->int_ip, - &pcp_msg_info->sender_ip, - sizeof(pcp_msg_info->sender_ip)) != 0) { - pcp_msg_info->result_code = PCP_ERR_ADDRESS_MISMATCH; - return 0; + if (pcp_msg_info->thirdp_ip) { + if (!GETFLAG(PCP_ALLOWTHIRDPARTYMASK)) { + pcp_msg_info->result_code = PCP_ERR_UNSUPP_OPTION; + return 0; + } + + /* RFC687, section 13.1 - if sender ip == THIRD_PARTY, + * it's an error. */ + if (memcmp(pcp_msg_info->thirdp_ip, + &pcp_msg_info->sender_ip, + sizeof(pcp_msg_info->sender_ip)) == 0) { + pcp_msg_info->result_code = PCP_ERR_MALFORMED_REQUEST; + return 0; + } + } else { + /* RFC 6887, section 8.2: MUST return address mismatch if NAT + * in middle. */ + if (memcmp(pcp_msg_info->int_ip, + &pcp_msg_info->sender_ip, + sizeof(pcp_msg_info->sender_ip)) != 0) { + pcp_msg_info->result_code = PCP_ERR_ADDRESS_MISMATCH; + return 0; + } } /* protocol zero means 'all protocols' : internal port MUST be zero */