Fix bug regarding negative Content-Length headers.

Change-Id: Ib8e2a5271c33f57429a9683db233610416887ea3
This commit is contained in:
gholt 2012-01-31 16:58:00 +00:00
parent a196386ee6
commit 17b3506741
2 changed files with 20 additions and 0 deletions

View File

@ -1807,6 +1807,9 @@ class BaseApplication(object):
:param req: webob.Request object
"""
try:
if req.content_length and req.content_length < 0:
return HTTPBadRequest(request=req,
body='Invalid Content-Length')
try:
controller, path_parts = self.get_controller(req.path)
except ValueError:

View File

@ -706,6 +706,23 @@ class TestProxyServer(unittest.TestCase):
resp = app.handle_request(req)
self.assert_(called[0])
def test_negative_content_length(self):
swift_dir = mkdtemp()
try:
baseapp = proxy_server.BaseApplication({'swift_dir': swift_dir},
FakeMemcache(), NullLoggingHandler(), FakeRing(), FakeRing(),
FakeRing())
resp = baseapp.handle_request(
Request.blank('/', environ={'CONTENT_LENGTH': '-1'}))
self.assertEquals(resp.status, '400 Bad Request')
self.assertEquals(resp.body, 'Invalid Content-Length')
resp = baseapp.handle_request(
Request.blank('/', environ={'CONTENT_LENGTH': '-123'}))
self.assertEquals(resp.status, '400 Bad Request')
self.assertEquals(resp.body, 'Invalid Content-Length')
finally:
rmtree(swift_dir, ignore_errors=True)
class TestObjectController(unittest.TestCase):