1From f7d268864a2660b7239b9a8ff5ad37faeeb751ba Mon Sep 17 00:00:00 2001 2From: Jouni Malinen <jouni@codeaurora.org> 3Date: Wed, 3 Jun 2020 22:41:02 +0300 4Subject: [PATCH 2/3] WPS UPnP: Fix event message generation using a long URL 5 path 6 7More than about 700 character URL ended up overflowing the wpabuf used 8for building the event notification and this resulted in the wpabuf 9buffer overflow checks terminating the hostapd process. Fix this by 10allocating the buffer to be large enough to contain the full URL path. 11However, since that around 700 character limit has been the practical 12limit for more than ten years, start explicitly enforcing that as the 13limit or the callback URLs since any longer ones had not worked before 14and there is no need to enable them now either. 15 16Signed-off-by: Jouni Malinen <jouni@codeaurora.org> 17--- 18 src/wps/wps_upnp.c | 9 +++++++-- 19 src/wps/wps_upnp_event.c | 3 ++- 20 2 files changed, 9 insertions(+), 3 deletions(-) 21 22diff --git a/src/wps/wps_upnp.c b/src/wps/wps_upnp.c 23index 7d4b7439940e..ab685d52ecab 100644 24--- a/src/wps/wps_upnp.c 25+++ b/src/wps/wps_upnp.c 26@@ -328,9 +328,14 @@ static void subscr_addr_add_url(struct subscription *s, const char *url, 27 int rerr; 28 size_t host_len, path_len; 29 30- /* url MUST begin with http: */ 31- if (url_len < 7 || os_strncasecmp(url, "http://", 7)) 32+ /* URL MUST begin with HTTP scheme. In addition, limit the length of 33+ * the URL to 700 characters which is around the limit that was 34+ * implicitly enforced for more than 10 years due to a bug in 35+ * generating the event messages. */ 36+ if (url_len < 7 || os_strncasecmp(url, "http://", 7) || url_len > 700) { 37+ wpa_printf(MSG_DEBUG, "WPS UPnP: Reject an unacceptable URL"); 38 goto fail; 39+ } 40 url += 7; 41 url_len -= 7; 42 43diff --git a/src/wps/wps_upnp_event.c b/src/wps/wps_upnp_event.c 44index d7e6edcc6503..08a23612f338 100644 45--- a/src/wps/wps_upnp_event.c 46+++ b/src/wps/wps_upnp_event.c 47@@ -147,7 +147,8 @@ static struct wpabuf * event_build_message(struct wps_event_ *e) 48 struct wpabuf *buf; 49 char *b; 50 51- buf = wpabuf_alloc(1000 + wpabuf_len(e->data)); 52+ buf = wpabuf_alloc(1000 + os_strlen(e->addr->path) + 53+ wpabuf_len(e->data)); 54 if (buf == NULL) 55 return NULL; 56 wpabuf_printf(buf, "NOTIFY %s HTTP/1.1\r\n", e->addr->path); 57-- 582.20.1 59 60