Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error parsing HTTP header with an empty value #5

Closed
wants to merge 1 commit into from
Closed

Error parsing HTTP header with an empty value #5

wants to merge 1 commit into from

Conversation

SeasonLee
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants