diff options
author | shadchin <[email protected]> | 2024-12-03 17:05:42 +0300 |
---|---|---|
committer | shadchin <[email protected]> | 2024-12-03 18:21:15 +0300 |
commit | 6388569551ef4720bdcd3f07af43fedbecabc847 (patch) | |
tree | 279445f9bbee9b4f7b518fde918e49b4c00566c0 /contrib/restricted/aws/aws-c-common/source | |
parent | 528eb8de83d25bf28f3d4a1202155523477ad4ac (diff) |
Update contrib/restricted/aws/aws-c-common to 0.8.23
commit_hash:ee9e58d849fe0a4add15cf37c9a8899e88291b18
Diffstat (limited to 'contrib/restricted/aws/aws-c-common/source')
8 files changed, 64 insertions, 13 deletions
diff --git a/contrib/restricted/aws/aws-c-common/source/allocator_sba.c b/contrib/restricted/aws/aws-c-common/source/allocator_sba.c index 4ebd6551f18..91a478f4f5e 100644 --- a/contrib/restricted/aws/aws-c-common/source/allocator_sba.c +++ b/contrib/restricted/aws/aws-c-common/source/allocator_sba.c @@ -6,6 +6,7 @@ #include <aws/common/allocator.h> #include <aws/common/array_list.h> #include <aws/common/assert.h> +#include <aws/common/macros.h> #include <aws/common/mutex.h> /* @@ -405,7 +406,7 @@ static void *s_sba_alloc(struct small_block_allocator *sba, size_t size) { return aws_mem_acquire(sba->allocator, size); } -static void s_sba_free(struct small_block_allocator *sba, void *addr) { +AWS_SUPPRESS_ASAN AWS_SUPPRESS_TSAN static void s_sba_free(struct small_block_allocator *sba, void *addr) { if (!addr) { return; } diff --git a/contrib/restricted/aws/aws-c-common/source/array_list.c b/contrib/restricted/aws/aws-c-common/source/array_list.c index 45c8a3cc76f..b6ea5a09013 100644 --- a/contrib/restricted/aws/aws-c-common/source/array_list.c +++ b/contrib/restricted/aws/aws-c-common/source/array_list.c @@ -206,3 +206,11 @@ void aws_array_list_swap(struct aws_array_list *AWS_RESTRICT list, size_t a, siz aws_array_list_mem_swap(item1, item2, list->item_size); AWS_POSTCONDITION(aws_array_list_is_valid(list)); } + +void aws_array_list_sort(struct aws_array_list *AWS_RESTRICT list, aws_array_list_comparator_fn *compare_fn) { + AWS_PRECONDITION(aws_array_list_is_valid(list)); + if (list->data) { + qsort(list->data, aws_array_list_length(list), list->item_size, compare_fn); + } + AWS_POSTCONDITION(aws_array_list_is_valid(list)); +} diff --git a/contrib/restricted/aws/aws-c-common/source/file.c b/contrib/restricted/aws/aws-c-common/source/file.c index 5f490003a03..01eb0a6afde 100644 --- a/contrib/restricted/aws/aws-c-common/source/file.c +++ b/contrib/restricted/aws/aws-c-common/source/file.c @@ -87,6 +87,19 @@ bool aws_is_any_directory_separator(char value) { return value == '\\' || value == '/'; } +void aws_normalize_directory_separator(struct aws_byte_buf *path) { + AWS_PRECONDITION(aws_byte_buf_is_valid(path)); + + const char local_platform_separator = aws_get_platform_directory_separator(); + for (size_t i = 0; i < path->len; ++i) { + if (aws_is_any_directory_separator((char)path->buffer[i])) { + path->buffer[i] = local_platform_separator; + } + } + + AWS_POSTCONDITION(aws_byte_buf_is_valid(path)); +} + struct aws_directory_iterator { struct aws_linked_list list_data; struct aws_allocator *allocator; diff --git a/contrib/restricted/aws/aws-c-common/source/posix/device_random.c b/contrib/restricted/aws/aws-c-common/source/posix/device_random.c index f446002231b..23ab1cd7b44 100644 --- a/contrib/restricted/aws/aws-c-common/source/posix/device_random.c +++ b/contrib/restricted/aws/aws-c-common/source/posix/device_random.c @@ -35,23 +35,40 @@ static void s_init_rand(void *user_data) { } } -static int s_fallback_device_random_buffer(struct aws_byte_buf *output) { +int aws_device_random_buffer_append(struct aws_byte_buf *output, size_t n) { + AWS_PRECONDITION(aws_byte_buf_is_valid(output)); aws_thread_call_once(&s_rand_init, s_init_rand, NULL); - size_t diff = output->capacity - output->len; + size_t space_available = output->capacity - output->len; + if (space_available < n) { + AWS_POSTCONDITION(aws_byte_buf_is_valid(output)); + return aws_raise_error(AWS_ERROR_SHORT_BUFFER); + } - ssize_t amount_read = read(s_rand_fd, output->buffer + output->len, diff); + size_t original_len = output->len; - if (amount_read != diff) { - return aws_raise_error(AWS_ERROR_RANDOM_GEN_FAILED); - } + /* read() can fail if N is too large (e.g. x64 macos fails if N > INT32_MAX), + * so work in reasonably sized chunks. */ + while (n > 0) { + size_t capped_n = aws_min_size(n, 1024 * 1024 * 1024 * 1 /* 1GiB */); + + ssize_t amount_read = read(s_rand_fd, output->buffer + output->len, capped_n); - output->len += diff; + if (amount_read <= 0) { + output->len = original_len; + AWS_POSTCONDITION(aws_byte_buf_is_valid(output)); + return aws_raise_error(AWS_ERROR_RANDOM_GEN_FAILED); + } + + output->len += amount_read; + n -= amount_read; + } + AWS_POSTCONDITION(aws_byte_buf_is_valid(output)); return AWS_OP_SUCCESS; } int aws_device_random_buffer(struct aws_byte_buf *output) { - return s_fallback_device_random_buffer(output); + return aws_device_random_buffer_append(output, output->capacity - output->len); } diff --git a/contrib/restricted/aws/aws-c-common/source/posix/file.c b/contrib/restricted/aws/aws-c-common/source/posix/file.c index e8b39c509c3..f8dbbd7e125 100644 --- a/contrib/restricted/aws/aws-c-common/source/posix/file.c +++ b/contrib/restricted/aws/aws-c-common/source/posix/file.c @@ -245,6 +245,14 @@ struct aws_string *aws_get_home_directory(struct aws_allocator *allocator) { aws_mem_release(allocator, buf); } buf = aws_mem_acquire(allocator, bufsize); + /* Note: on newer GCC with address sanitizer on, getpwuid_r triggers + * build error, since buf can in theory be null, but buffsize will be + * nonzero. following if statement works around that. */ + if (buf == NULL) { + aws_raise_error(AWS_ERROR_GET_HOME_DIRECTORY_FAILED); + return NULL; + } + status = getpwuid_r(uid, &pwd, buf, bufsize, &result); } diff --git a/contrib/restricted/aws/aws-c-common/source/promise.c b/contrib/restricted/aws/aws-c-common/source/promise.c index 444623d625d..7c8572457ea 100644 --- a/contrib/restricted/aws/aws-c-common/source/promise.c +++ b/contrib/restricted/aws/aws-c-common/source/promise.c @@ -82,8 +82,11 @@ void aws_promise_complete(struct aws_promise *promise, void *value, void (*dtor) promise->value = value; promise->dtor = dtor; promise->complete = true; - aws_mutex_unlock(&promise->mutex); + /* Notify before unlocking to prevent a race condition where the recipient spuriously + * awakens after the unlock, sees a fulfilled promise, and attempts to free its resources + * before the notification has actually occured. */ aws_condition_variable_notify_all(&promise->cv); + aws_mutex_unlock(&promise->mutex); } void aws_promise_fail(struct aws_promise *promise, int error_code) { @@ -92,8 +95,8 @@ void aws_promise_fail(struct aws_promise *promise, int error_code) { AWS_FATAL_ASSERT(!promise->complete && "aws_promise_fail: cannot complete a promise more than once"); promise->error_code = error_code; promise->complete = true; - aws_mutex_unlock(&promise->mutex); aws_condition_variable_notify_all(&promise->cv); + aws_mutex_unlock(&promise->mutex); } int aws_promise_error_code(struct aws_promise *promise) { diff --git a/contrib/restricted/aws/aws-c-common/source/thread_shared.c b/contrib/restricted/aws/aws-c-common/source/thread_shared.c index a0d19adfe06..cbceb428eda 100644 --- a/contrib/restricted/aws/aws-c-common/source/thread_shared.c +++ b/contrib/restricted/aws/aws-c-common/source/thread_shared.c @@ -40,8 +40,8 @@ void aws_thread_increment_unjoined_count(void) { void aws_thread_decrement_unjoined_count(void) { aws_mutex_lock(&s_managed_thread_lock); --s_unjoined_thread_count; - aws_mutex_unlock(&s_managed_thread_lock); aws_condition_variable_notify_one(&s_managed_thread_signal); + aws_mutex_unlock(&s_managed_thread_lock); } size_t aws_thread_get_managed_thread_count(void) { diff --git a/contrib/restricted/aws/aws-c-common/source/uri.c b/contrib/restricted/aws/aws-c-common/source/uri.c index 1fafc9492e6..cefe57e8768 100644 --- a/contrib/restricted/aws/aws-c-common/source/uri.c +++ b/contrib/restricted/aws/aws-c-common/source/uri.c @@ -114,7 +114,8 @@ int aws_uri_init_from_builder_options( buffer_size += 1; for (size_t i = 0; i < query_len; ++i) { struct aws_uri_param *uri_param_ptr = NULL; - aws_array_list_get_at_ptr(options->query_params, (void **)&uri_param_ptr, i); + int result = aws_array_list_get_at_ptr(options->query_params, (void **)&uri_param_ptr, i); + AWS_FATAL_ASSERT(result == AWS_OP_SUCCESS); /* 2 == 1 for '&' and 1 for '='. who cares if we over-allocate a little? */ buffer_size += uri_param_ptr->key.len + uri_param_ptr->value.len + 2; } |