Fix object copy with empty source

When s3 client make a copy request with empty copy source,
current swift3 will return a 500 error. This is caused from
a lack of header validation.

This fixes the behavior to make a 400 Bad Request (InvalidArgument).

Change-Id: I60c7e480582f5b9258433306bbf228b7291e6236
This commit is contained in:
Kota Tsuyuzaki
2014-12-08 23:40:26 -08:00
parent 3c40629f48
commit c330da7081
5 changed files with 81 additions and 14 deletions

View File

@@ -58,14 +58,13 @@ class ObjectController(Controller):
Handle PUT Object and PUT Object (Copy) request
"""
if CONF.s3_acl:
if 'HTTP_X_AMZ_COPY_SOURCE' in req.environ:
src_path = req.environ['HTTP_X_AMZ_COPY_SOURCE']
src_path = src_path if src_path[0] == '/' else ('/' + src_path)
if 'X-Amz-Copy-Source' in req.headers:
src_path = req.headers['X-Amz-Copy-Source']
src_path = src_path if src_path.startswith('/') else \
('/' + src_path)
src_bucket, src_obj = split_path(src_path, 0, 2, True)
req.get_response(self.app, 'HEAD', src_bucket, src_obj,
permission='READ')
b_resp = req.get_response(self.app, 'HEAD', obj='')
# To avoid overwriting the existing object by unauthorized user,
# we send HEAD request first before writing the object to make
@@ -83,11 +82,11 @@ class ObjectController(Controller):
resp = req.get_response(self.app)
if 'HTTP_X_COPY_FROM' in req.environ:
if 'X-Amz-Copy-Source' in req.headers:
elem = Element('CopyObjectResult')
SubElement(elem, 'ETag').text = '"%s"' % resp.etag
body = tostring(elem, use_s3ns=False)
return HTTPOk(body=body)
return HTTPOk(body=body, headers=resp.headers)
resp.status = HTTP_OK