Fix a crash when parsing empty HTTP headers

This commit is contained in:
Peter Thorson
2014-01-26 19:39:55 -06:00
parent 4393a2562b
commit e44463583b
3 changed files with 6 additions and 0 deletions

View File

@@ -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

View File

@@ -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 ) {

View File

@@ -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());