Handle invalid content length headers.

This commit is contained in:
Aldo Cortesi 2012-07-22 12:30:10 +12:00
parent 7a49cdfef3
commit 8d8ede7e26
2 changed files with 20 additions and 3 deletions

View File

@ -42,9 +42,20 @@ class PathodHandler(tcp.BaseHandler):
method, path, httpversion = parts method, path, httpversion = parts
headers = http.read_headers(self.rfile) headers = http.read_headers(self.rfile)
content = http.read_http_body_request( try:
self.rfile, self.wfile, headers, httpversion, None content = http.read_http_body_request(
self.rfile, self.wfile, headers, httpversion, None
)
except http.HttpError, s:
s = str(s)
self.info(s)
self.server.add_log(
dict(
type = "error",
msg = s
) )
)
return
crafted = None crafted = None
for i in self.server.anchors: for i in self.server.anchors:

View File

@ -1,6 +1,6 @@
import requests import requests
from libpathod import pathod, test, version, pathoc from libpathod import pathod, test, version, pathoc
from netlib import tcp from netlib import tcp, http
import tutils import tutils
class _TestApplication: class _TestApplication:
@ -115,6 +115,12 @@ class _DaemonTests:
assert l["type"] == "error" assert l["type"] == "error"
assert "foo" in l["msg"] assert "foo" in l["msg"]
def test_invalid_body(self):
tutils.raises(http.HttpError, self.pathoc, "get:/:h'content-length'='foo'")
l = self.d.log()[0]
assert l["type"] == "error"
assert "Invalid" in l["msg"]
class TestDaemon(_DaemonTests): class TestDaemon(_DaemonTests):