Skip to content

Commit 194403b

Browse files
committed
fix: cmd_object_put check not exists bucket
In the cmd_object_put function, after checking the type of the URL, verify whether the passed bucket exists. The reason for doing this is that in a self-built S3 Server, I attempted to upload to a non-existent bucket using s3cmd, similar to 's3cmd put hello s3://b02', where b02does not exist, but the operation still succeeded(and the file could even be downloaded). This issue arises due to a design flaw in our S3 Server. $ ./s3cmd put setup.cfg s3://b02 upload: 'setup.cfg' -> 's3://b02/setup.cfg' [1 of 1] 56 of 56 100% in 0s 11.63 KB/s done $ mc put setup.cfg myio/b02 mc: <ERROR> unable to upload. Bucket `b02` does not exist. However, similar clients like the MinIO client would directly return an error stating that the bucket b02 does not exist.Therefore, I believe it is necessary for s3cmd to include this check. $ ./s3cmd put setup.cfg s3://b02 ERROR: Bucket 'b02' does not exist Signed-off-by: chenmiao <[email protected]>
1 parent d427537 commit 194403b

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

s3cmd

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,13 @@ def cmd_object_put(args):
402402
raise ParameterError("Destination must be S3Uri. Got: %s" % destination_base_uri)
403403
destination_base = destination_base_uri.uri()
404404

405+
check_uri = S3UriS3(destination_base)
406+
check_bucket = check_uri.bucket()
407+
408+
if not any(bucket['Name'] == check_bucket for bucket in s3.list_all_buckets()['list']):
409+
error(u"Bucket '%s' does not exist" % check_bucket)
410+
return EX_NOTFOUND
411+
405412
if len(args) == 0:
406413
raise ParameterError("Nothing to upload. Expecting a local file or directory.")
407414

@@ -3612,7 +3619,7 @@ if __name__ == '__main__':
36123619
from S3.Config import Config
36133620
from S3.SortedDict import SortedDict
36143621
from S3.FileDict import FileDict
3615-
from S3.S3Uri import S3Uri
3622+
from S3.S3Uri import S3Uri, S3UriS3
36163623
from S3 import Utils
36173624
from S3.BaseUtils import (formatDateTime, getPrettyFromXml,
36183625
encode_to_s3, decode_from_s3, s3path)

0 commit comments

Comments
 (0)