summaryrefslogtreecommitdiff
path: root/modules/extra/m_httpd.cpp
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2013-08-23 00:57:36 -0400
committerAdam <Adam@anope.org>2013-08-23 00:57:36 -0400
commit154fa25e8fc33c2ce77cb0612c1587cec4f32300 (patch)
treef869c58dbd8252170f12faa59928ce991d191792 /modules/extra/m_httpd.cpp
parent2b1f75a3132b6a5719db188311d63154c287b601 (diff)
Fix m_httpd handling fragmented http requests
Diffstat (limited to 'modules/extra/m_httpd.cpp')
-rw-r--r--modules/extra/m_httpd.cpp21
1 files changed, 13 insertions, 8 deletions
diff --git a/modules/extra/m_httpd.cpp b/modules/extra/m_httpd.cpp
index 03e130068..bdb3ed602 100644
--- a/modules/extra/m_httpd.cpp
+++ b/modules/extra/m_httpd.cpp
@@ -45,6 +45,7 @@ class MyHTTPClient : public HTTPClient
Reference<HTTPPage> page;
Anope::string ip;
+ Anope::string inbuf;
unsigned content_length;
Anope::string post_data;
@@ -111,19 +112,23 @@ class MyHTTPClient : public HTTPClient
bool Read(const char *buffer, size_t l) anope_override
{
- Anope::string buf(buffer, l);
+ inbuf.append(buffer, l);
- if (!this->header_done)
+ for (size_t nl; !this->header_done && (nl = inbuf.find('\n')) != Anope::string::npos;)
{
- Anope::string token;
- sepstream sep(buf, '\n');
- while (sep.GetToken(token) && !token.trim().empty())
+ Anope::string token = inbuf.substr(0, nl).trim();
+ inbuf = inbuf.substr(nl + 1);
+
+ if (token.empty())
+ this->header_done = true;
+ else
this->Read(token);
- this->header_done = true;
- buf = sep.GetRemaining();
}
- this->post_data += buf;
+ if (!this->header_done)
+ return true;
+
+ this->post_data += inbuf;
if (this->post_data.length() >= this->content_length)
{