From 6ca8ee1dcf1c6bbdf4635db7b77b4635974ea875 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Thu, 7 Feb 2013 11:00:15 +0100 Subject: [PATCH] minissdp.c: ignore SSDP packets missing the MX: header in UPNP_STRICT mode --- miniupnpd/Changelog.txt | 1 + miniupnpd/minissdp.c | 25 ++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/miniupnpd/Changelog.txt b/miniupnpd/Changelog.txt index e2bf08d..2a03aee 100644 --- a/miniupnpd/Changelog.txt +++ b/miniupnpd/Changelog.txt @@ -3,6 +3,7 @@ $Id: Changelog.txt,v 1.328 2013/02/06 23:37:27 nanard Exp $ 2013/02/07: Add DATE: header in SSDP packets Fix SSDP packets sent with uuid as ST: header to conform to UDA + ignore SSDP packets missing the MX: header in UPNP_STRICT mode VERSION 1.8 : released on 2013/02/06 diff --git a/miniupnpd/minissdp.c b/miniupnpd/minissdp.c index 58ea9e9..de30bdc 100644 --- a/miniupnpd/minissdp.c +++ b/miniupnpd/minissdp.c @@ -566,10 +566,11 @@ ProcessSSDPData(int s, const char *bufr, int n, char sender_str[64]; char ver_str[4]; const char * announced_host = NULL; -#ifdef ENABLE_IPV6 #ifdef UPNP_STRICT +#ifdef ENABLE_IPV6 char announced_host_buf[64]; #endif + int mx_value = -1; #endif /* get the string representation of the sender address */ @@ -613,7 +614,29 @@ ProcessSSDPData(int s, const char *bufr, int n, /*while(bufr[i+j]!='\r') j++;*/ /*syslog(LOG_INFO, "%.*s", j, bufr+i);*/ } +#ifdef UPNP_STRICT + else if((i < n - 3) && (strncasecmp(bufr+i, "mx:", 3) == 0)) + { + const char * mx; + int mx_len; + mx = bufr+i+3; + mx_len = 0; + while((*mx == ' ' || *mx == '\t') && (mx < bufr + n)) + mx++; + while(mx[mx_len]!='\r' && mx[mx_len]!='\n' + && (mx + mx_len < bufr + n)) + mx_len++; + mx_value = atoi(mx); + syslog(LOG_DEBUG, "MX: %.*s (value=%d)", mx_len, mx, mx_value); + } +#endif } +#ifdef UPNP_STRICT + if(mx_value < 0) { + syslog(LOG_INFO, "ignoring SSDP packet missing MX: header"); + return; + } +#endif /*syslog(LOG_INFO, "SSDP M-SEARCH packet received from %s", sender_str );*/ if(st && (st_len > 0))