Error parsing HTTP header with an empty value #5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Sending a HTTP request to muduo::net::HttpServer.cc(using the httpserver_test) will result in crashing of httpserver_test.
Testcase in which the
User-Agent
field has an empty value:"GET /hello HTTP/1.1\r\nHost:localhost\r\nUser-Agent:\r\nAccept-Encoding: gzip,deflate,sdch\r\nAccept-Language: en-us,fr\r\nAccept-Charset: iso-8859-1,_,utf-8\r\n\r\n"
_The backtrace of gdb is as following:*
terminate called after throwing an instance of 'std::length_error'
what(): basic_string::_S_create
Program received signal SIGABRT, Aborted.
#6 0x00007ffff770d307 in std::__throw_length_error(char const*) () from /usr/lib/libstdc++.so.6
#7 0x00007ffff774eb42 in std::string::Rep::S_create(unsigned long, unsigned long, std::allocator const&) () from /usr/lib/libstdc++.so.6
#8 0x000000000045a6fb in std::string::S_construct<char const*> (__beg=0x6a8ac2 "Accept-Encoding: gzip,deflate,sdch\r\nAccept-Language: en-us,fr\r\nAccept-Charset: iso-8859-1,,utf-8\r\n\r\n",__end=0x6a8ac0 "\r\nAccept-Encoding: gzip,deflate,sdch\r\nAccept-Language: en-us,fr\r\nAccept-Charset: iso-8859-1,,utf-8\r\n\r\n",__a=...) at /usr/include/c++/4.4/bits/basic_string.tcc:139
#9 0x00000000004599d7 in std::string::S_construct_aux<char const*> (__beg=0x6a8ac2 "Accept-Encoding: gzip,deflate,sdch\r\nAccept-Language: en-us,fr\r\nAccept-Charset: iso-8859-1,,utf-8\r\n\r\n",__end=0x6a8ac0 "\r\nAccept-Encoding: gzip,deflate,sdch\r\nAccept-Language: en-us,fr\r\nAccept-Charset: iso-8859-1,,utf-8\r\n\r\n",__a=...) at /usr/include/c++/4.4/bits/basic_string.h:1543
#10 0x00000000004586ba in std::string::S_construct<char const*> (__beg=0x6a8ac2 "Accept-Encoding: gzip,deflate,sdch\r\nAccept-Language: en-us,fr\r\nAccept-Charset: iso-8859-1,,utf-8\r\n\r\n",__end=0x6a8ac0 "\r\nAccept-Encoding: gzip,deflate,sdch\r\nAccept-Language: en-us,fr\r\nAccept-Charset: iso-8859-1,,utf-8\r\n\r\n",__a=...) at /usr/include/c++/4.4/bits/basic_string.h:1559
#11 0x00000000004579f7 in basic_string<char const*> (this=0x7fffffffa360,__beg=0x6a8ac2 "Accept-Encoding: gzip,deflate,sdch\r\nAccept-Language: en-us,fr\r\nAccept-Charset: iso-8859-1,,utf-8\r\n\r\n",__end=0x6a8ac0 "\r\nAccept-Encoding: gzip,deflate,sdch\r\nAccept-Language: en-us,fr\r\nAccept-Charset: iso-8859-1,,utf-8\r\n\r\n",__a=...) at /usr/include/c++/4.4/bits/basic_string.tcc:230
#12 0x0000000000456e12 in muduo::net::HttpRequest::addHeader (this=0x6a93b0,start=0x6a8ab5 "User-Agent:\r\nAccept-Encoding: gzip,deflate,sdch\r\nAccept-Language: en-us,fr\r\nAccept-Charset: iso-8859-1,,utf-8\r\n\r\n",colon=0x6a8ac2 "Accept-Encoding: gzip,deflate,sdch\r\nAccept-Language: en-us,fr\r\nAccept-Charset: iso-8859-1,,utf-8\r\n\r\n",end=0x6a8ac0 "\r\nAccept-Encoding: gzip,deflate,sdch\r\nAccept-Language: en-us,fr\r\nAccept-Charset: iso-8859-1,,utf-8\r\n\r\n") at /_/muduo/net/http/HttpRequest.h:135
#13 0x000000000045536e in parseRequest (buf=0x6a8a00, context=0x6a93a8, receiveTime=...) at //muduo/net/http/HttpServer.cc:96
#14 0x0000000000455c95 in muduo::net::HttpServer::onMessage (this=0x7fffffffe880, conn=..., buf=0x6a8a00, receiveTime=...) at /******/muduo/net/http/HttpServer.cc:165
According to the protocol of HTTP, the 'field-value' of a HTTP header may be an empty string.
At /muduo/net/http/HttpRequest.h:131 , the pointer
colon
is not supposed to pass the pointerend
.