From 92992c7eaca35f172599b9d4b820ffe55d0b06c3 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sat, 18 Feb 2012 20:35:06 +0000 Subject: [PATCH] fix upnp snprintf issue --- src/upnp.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/upnp.cpp b/src/upnp.cpp index cae0cb371..9849acba3 100644 --- a/src/upnp.cpp +++ b/src/upnp.cpp @@ -357,15 +357,14 @@ void upnp::on_reply(udp::endpoint const& from, char* buffer } else { - char msg[200]; + char msg[400]; int num_chars = snprintf(msg, sizeof(msg) , "ignoring response from: %s. IP is not on local network. " , print_endpoint(from).c_str()); - log(msg, l); std::vector net = enum_net_interfaces(m_io_service, ec); for (std::vector::const_iterator i = net.begin() - , end(net.end()); i != end; ++i) + , end(net.end()); i != end && num_chars < sizeof(msg); ++i) { num_chars += snprintf(msg + num_chars, sizeof(msg) - num_chars, "(%s,%s) " , print_address(i->interface_address).c_str(), print_address(i->netmask).c_str()); @@ -396,9 +395,8 @@ void upnp::on_reply(udp::endpoint const& from, char* buffer int num_chars = snprintf(msg, sizeof(msg), "ignoring response from: %s: IP is not a router. " , print_endpoint(from).c_str()); for (std::vector::const_iterator i = routes.begin() - , end(routes.end()); i != end; ++i) + , end(routes.end()); i != end && num_chars < sizeof(msg); ++i) { - if (num_chars >= int(sizeof(msg)-1)) break; num_chars += snprintf(msg + num_chars, sizeof(msg) - num_chars, "(%s,%s) " , print_address(i->gateway).c_str(), print_address(i->netmask).c_str()); }