From d74505ed86cb7613d87e3b7ff1e097302bf52c83 Mon Sep 17 00:00:00 2001 From: eidheim Date: Mon, 3 Aug 2015 21:15:26 +0200 Subject: [PATCH] Fixed crash on server when Content-Length parameter was set to a non-number. --- server_http.hpp | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/server_http.hpp b/server_http.hpp index 25765ed..0fc5cc2 100644 --- a/server_http.hpp +++ b/server_http.hpp @@ -272,16 +272,21 @@ namespace SimpleWeb { std::shared_ptr timer; if(timeout_content>0) timer=set_timeout_on_socket(socket, timeout_content); - - boost::asio::async_read(*socket, request->streambuf, - boost::asio::transfer_exactly(stoull(it->second)-num_additional_bytes), - [this, socket, request, timer] - (const boost::system::error_code& ec, size_t /*bytes_transferred*/) { - if(timeout_content>0) - timer->cancel(); - if(!ec) - find_resource(socket, request); - }); + try { + auto content_length=stoull(it->second); + boost::asio::async_read(*socket, request->streambuf, + boost::asio::transfer_exactly(stoull(it->second)-num_additional_bytes), + [this, socket, request, timer] + (const boost::system::error_code& ec, size_t /*bytes_transferred*/) { + if(timeout_content>0) + timer->cancel(); + if(!ec) + find_resource(socket, request); + }); + } + catch(const std::exception& e) { + std::cerr << e.what() << std::endl; + } } else { find_resource(socket, request);