verify error code for empty bucket name

This commit is contained in:
obdev
2024-07-12 10:55:20 +00:00
committed by ob-robot
parent 5008e063af
commit f3c67ff2df
4 changed files with 11 additions and 3 deletions

View File

@ -192,7 +192,11 @@ int ObCosWrapperHandle::build_bucket_and_object_name(const ObString &uri)
if ('/' == *(uri.ptr() + bucket_end)) { if ('/' == *(uri.ptr() + bucket_end)) {
ObString::obstr_size_t bucket_length = bucket_end - bucket_start; ObString::obstr_size_t bucket_length = bucket_end - bucket_start;
//must end with '\0' //must end with '\0'
if (OB_FAIL(databuff_printf(bucket_name_buff, OB_MAX_URI_LENGTH, "%.*s", bucket_length, uri.ptr() + bucket_start))) { if (OB_UNLIKELY(bucket_length <= 0)) {
ret = OB_INVALID_ARGUMENT;
OB_LOG(WARN,"bucket is empty", K(ret), K(bucket_end), K(bucket_start), K(uri));
} else if (OB_FAIL(databuff_printf(bucket_name_buff, OB_MAX_URI_LENGTH, "%.*s",
bucket_length, uri.ptr() + bucket_start))) {
OB_LOG(WARN, "fail to deep copy bucket", K(uri), K(bucket_start), K(bucket_length), K(ret)); OB_LOG(WARN, "fail to deep copy bucket", K(uri), K(bucket_start), K(bucket_length), K(ret));
} else { } else {
bucket_name_.assign_ptr(bucket_name_buff, strlen(bucket_name_buff) + 1);// must include '\0' bucket_name_.assign_ptr(bucket_name_buff, strlen(bucket_name_buff) + 1);// must include '\0'

View File

@ -103,7 +103,7 @@ int handle_listed_directory(ObBaseDirEntryOperator &op,
return ret; return ret;
} }
static int get_storage_prefix_from_path(const common::ObString &uri, const char *&prefix) int get_storage_prefix_from_path(const common::ObString &uri, const char *&prefix)
{ {
int ret = OB_SUCCESS; int ret = OB_SUCCESS;
if (uri.prefix_match(OB_OSS_PREFIX)) { if (uri.prefix_match(OB_OSS_PREFIX)) {

View File

@ -53,6 +53,7 @@ int handle_listed_object(ObBaseDirEntryOperator &op,
const char *obj_name, const int64_t obj_name_len, const int64_t obj_size); const char *obj_name, const int64_t obj_name_len, const int64_t obj_size);
int handle_listed_directory(ObBaseDirEntryOperator &op, int handle_listed_directory(ObBaseDirEntryOperator &op,
const char *dir_name, const int64_t dir_name_len); const char *dir_name, const int64_t dir_name_len);
int get_storage_prefix_from_path(const common::ObString &uri, const char *&prefix);
int build_bucket_and_object_name(ObIAllocator &allocator, int build_bucket_and_object_name(ObIAllocator &allocator,
const ObString &uri, ObString &bucket, ObString &object); const ObString &uri, ObString &bucket, ObString &object);
int construct_fragment_full_name(const ObString &logical_appendable_object_name, int construct_fragment_full_name(const ObString &logical_appendable_object_name,

View File

@ -144,7 +144,10 @@ int get_bucket_object_name(const ObString &uri, ObString &bucket, ObString &obje
for (bucket_end = bucket_start; OB_SUCC(ret) && bucket_end < uri.length(); ++bucket_end) { for (bucket_end = bucket_start; OB_SUCC(ret) && bucket_end < uri.length(); ++bucket_end) {
if ('/' == *(uri.ptr() + bucket_end)) { if ('/' == *(uri.ptr() + bucket_end)) {
ObString::obstr_size_t bucket_length = bucket_end - bucket_start; ObString::obstr_size_t bucket_length = bucket_end - bucket_start;
if (OB_ISNULL(buf = reinterpret_cast<char *>(allocator.alloc(OB_MAX_URI_LENGTH)))) { if (OB_UNLIKELY(bucket_length <= 0)) {
ret = OB_INVALID_ARGUMENT;
OB_LOG(WARN,"bucket is empty", K(ret), K(bucket_end), K(bucket_start), K(uri));
} else if (OB_ISNULL(buf = reinterpret_cast<char *>(allocator.alloc(OB_MAX_URI_LENGTH)))) {
ret = OB_ALLOCATE_MEMORY_FAILED; ret = OB_ALLOCATE_MEMORY_FAILED;
OB_LOG(WARN,"allocate memory error", K(OB_MAX_URI_LENGTH), K(ret)); OB_LOG(WARN,"allocate memory error", K(OB_MAX_URI_LENGTH), K(ret));
} else { } else {