From e44463583b4a3b3ea435cfacbec9e64aa1036efa Mon Sep 17 00:00:00 2001 From: Peter Thorson Date: Sun, 26 Jan 2014 19:39:55 -0600 Subject: [PATCH] Fix a crash when parsing empty HTTP headers --- changelog.md | 1 + test/http/parser.cpp | 2 ++ websocketpp/http/parser.hpp | 3 +++ 3 files changed, 6 insertions(+) diff --git a/changelog.md b/changelog.md index e74efd1877..f00a93fd7d 100644 --- a/changelog.md +++ b/changelog.md @@ -25,6 +25,7 @@ HEAD - Bug: Fix handler allocation crash with multithreaded io_service. - Bug: Fixes incorrect whitespace handling in header parsing. #301 Thank you Wolfram Schroers for reporting +- Bug: Fix a crash when parsing empty HTTP headers. Thank you Thingol for reporting. 0.3.0-alpha4 - 2013-10-11 - HTTP requests ending normally are no longer logged as errors. Thank you Banaan diff --git a/test/http/parser.cpp b/test/http/parser.cpp index a5c13ea3bd..beaa8fb711 100644 --- a/test/http/parser.cpp +++ b/test/http/parser.cpp @@ -363,6 +363,7 @@ BOOST_AUTO_TEST_CASE( strip_lws ) { std::string test5 = " foo "; std::string test6 = " \r\n foo "; std::string test7 = " \t foo "; + std::string test8 = " \t "; BOOST_CHECK_EQUAL( websocketpp::http::parser::strip_lws(test1), "foo" ); BOOST_CHECK_EQUAL( websocketpp::http::parser::strip_lws(test2), "foo" ); @@ -371,6 +372,7 @@ BOOST_AUTO_TEST_CASE( strip_lws ) { BOOST_CHECK_EQUAL( websocketpp::http::parser::strip_lws(test5), "foo" ); BOOST_CHECK_EQUAL( websocketpp::http::parser::strip_lws(test6), "foo" ); BOOST_CHECK_EQUAL( websocketpp::http::parser::strip_lws(test7), "foo" ); + BOOST_CHECK_EQUAL( websocketpp::http::parser::strip_lws(test8), "" ); } BOOST_AUTO_TEST_CASE( case_insensitive_headers ) { diff --git a/websocketpp/http/parser.hpp b/websocketpp/http/parser.hpp index 771c53971e..281927637b 100644 --- a/websocketpp/http/parser.hpp +++ b/websocketpp/http/parser.hpp @@ -369,6 +369,9 @@ InputIterator extract_parameters(InputIterator begin, InputIterator end, inline std::string strip_lws(std::string const & input) { std::string::const_iterator begin = extract_all_lws(input.begin(),input.end()); + if (begin == input.end()) { + return std::string(); + } std::string::const_reverse_iterator end = extract_all_lws(input.rbegin(),input.rend()); return std::string(begin,end.base());