diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2012-07-22 12:30:10 +1200 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2012-07-22 12:30:10 +1200 |
commit | 8d8ede7e265591e94f6e2db5bf79f6b85e822912 (patch) | |
tree | f047a31003cea2b43fe9caa67681dadfbc62a2d3 | |
parent | 7a49cdfef3d9f5eeaecf6d6c8938f0bb8da7c15d (diff) | |
download | mitmproxy-8d8ede7e265591e94f6e2db5bf79f6b85e822912.tar.gz mitmproxy-8d8ede7e265591e94f6e2db5bf79f6b85e822912.tar.bz2 mitmproxy-8d8ede7e265591e94f6e2db5bf79f6b85e822912.zip |
Handle invalid content length headers.
-rw-r--r-- | libpathod/pathod.py | 15 | ||||
-rw-r--r-- | test/test_pathod.py | 8 |
2 files changed, 20 insertions, 3 deletions
diff --git a/libpathod/pathod.py b/libpathod/pathod.py index 026986bb..e4a14193 100644 --- a/libpathod/pathod.py +++ b/libpathod/pathod.py @@ -42,9 +42,20 @@ class PathodHandler(tcp.BaseHandler): method, path, httpversion = parts headers = http.read_headers(self.rfile) - content = http.read_http_body_request( - self.rfile, self.wfile, headers, httpversion, None + try: + 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 for i in self.server.anchors: diff --git a/test/test_pathod.py b/test/test_pathod.py index 1484efcd..86f37f01 100644 --- a/test/test_pathod.py +++ b/test/test_pathod.py @@ -1,6 +1,6 @@ import requests from libpathod import pathod, test, version, pathoc -from netlib import tcp +from netlib import tcp, http import tutils class _TestApplication: @@ -115,6 +115,12 @@ class _DaemonTests: assert l["type"] == "error" 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): |