Skip to content

Commit 7b7291a

Browse files
author
DenverM80
committed
Add test for max offset to not overflow buffer; fix put_bulk test regression
1 parent 083ef2c commit 7b7291a

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

src/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ add_library(ds3 SHARED
99
ds3_connection.h ds3_connection.c)
1010

1111
if (WIN32)
12-
#set(WINDOWS_VS_OUTPUT_DIR ${PROJECT_SOURCE_DIR}/win32/src/Debug)
12+
set(CMAKE_BUILD_TYPE Release)
1313
set(WINDOWS_VS_OUTPUT_DIR ${PROJECT_SOURCE_DIR}/win32/src/Release)
14+
#set(CMAKE_BUILD_TYPE Debug)
15+
#set(WINDOWS_VS_OUTPUT_DIR ${PROJECT_SOURCE_DIR}/win32/src/Debug)
1416

1517
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${WINDOWS_VS_OUTPUT_DIR})
1618
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${WINDOWS_VS_OUTPUT_DIR})

src/ds3_init_requests.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,7 @@
2626
#include "ds3_request.h"
2727
#include "ds3_net.h"
2828

29-
//The max size of an uint32_t should be 10 characters + NULL
30-
static const char UNSIGNED_LONG_BASE_10[] = "4294967296";
31-
static const unsigned int UNSIGNED_LONG_BASE_10_STR_LEN = sizeof(UNSIGNED_LONG_BASE_10) + 1;
32-
//The max size of an uint64_t should be 20 characters + NULL
33-
static const char UNSIGNED_LONG_LONG_BASE_10[] = "18446744073709551615";
34-
static const unsigned int UNSIGNED_LONG_LONG_BASE_10_STR_LEN = sizeof(UNSIGNED_LONG_LONG_BASE_10) + 1;
29+
static const unsigned int STRING_BUFFER_SIZE = 32;
3530

3631
static char* _get_ds3_bucket_acl_permission_str(ds3_bucket_acl_permission input) {
3732
if (input == DS3_BUCKET_ACL_PERMISSION_LIST) {
@@ -857,21 +852,21 @@ static void _set_query_param_flag(const ds3_request* _request, const char* key,
857852
}
858853

859854
static void _set_query_param_uint64_t(const ds3_request* _request, const char* key, uint64_t value) {
860-
char string_buffer[UNSIGNED_LONG_LONG_BASE_10_STR_LEN];
855+
char string_buffer[STRING_BUFFER_SIZE];
861856
memset(string_buffer, 0, sizeof(string_buffer));
862857
snprintf(string_buffer, sizeof(string_buffer), "%" PRIu64, value);
863858
_set_query_param(_request, key, string_buffer);
864859
}
865860

866861
static void _set_query_param_int(const ds3_request* _request, const char* key, int value) {
867-
char string_buffer[UNSIGNED_LONG_BASE_10_STR_LEN];
862+
char string_buffer[STRING_BUFFER_SIZE];
868863
memset(string_buffer, 0, sizeof(string_buffer));
869864
snprintf(string_buffer, sizeof(string_buffer), "%d", value);
870865
_set_query_param(_request, key, string_buffer);
871866
}
872867

873868
static void _set_query_param_float(const ds3_request* _request, const char* key, float value) {
874-
char string_buffer[UNSIGNED_LONG_BASE_10_STR_LEN];
869+
char string_buffer[STRING_BUFFER_SIZE];
875870
memset(string_buffer, 0, sizeof(string_buffer));
876871
snprintf(string_buffer, sizeof(string_buffer), "%f", value);
877872
_set_query_param(_request, key, string_buffer);

test/bucket_tests.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,23 @@
1515

1616
#include <stdio.h>
1717
#include "ds3.h"
18+
#include "ds3_request.h"
1819
#include "test.h"
1920
#include <boost/test/unit_test.hpp>
2021
#include <glib.h>
22+
#include <limits.h>
23+
24+
BOOST_AUTO_TEST_CASE( init_put_object_offset_unsigned_long_long ) {
25+
printf("-----Testing init PUT_OBJECT with max unsigned long long offset-------\n");
26+
27+
struct _ds3_request* request = ds3_init_put_object_request("Test_bucket", "test_object", 1024 * 1024);
28+
ds3_request_set_offset(request, ULLONG_MAX);
29+
30+
char* value = (char*)g_hash_table_lookup(request->query_params, "offset");
31+
printf(" request->query_params[\"offset\"]:%s\n", value);
32+
BOOST_CHECK(value != NULL);
33+
BOOST_CHECK(g_strcmp0(value, "18446744073709551615") == 0);
34+
}
2135

2236
BOOST_AUTO_TEST_CASE( bulk_put ) {
2337
printf("-----Testing Bulk PUT-------\n");
@@ -63,15 +77,15 @@ BOOST_AUTO_TEST_CASE( empty_folder ) {
6377
const char* objects[1] = {"empty-folder/"};
6478
ds3_bulk_object_list_response* object_list = ds3_convert_object_list_from_strings(objects, 1);
6579
ds3_request* request = ds3_init_put_bulk_job_spectra_s3_request(bucket_name, object_list);
66-
ds3_master_object_list_response* bulk_response = NULL;
80+
ds3_master_object_list_response* bulk_response;
6781
error = ds3_put_bulk_job_spectra_s3_request(client, request, &bulk_response);
6882
handle_error(error);
69-
ds3_master_object_list_response_free(bulk_response);
7083

7184
request = ds3_init_put_object_request(bucket_name, objects[0], 0);
7285
ds3_request_set_job(request, bulk_response->job_id->value);
73-
error = ds3_put_object_request(client, request, NULL, NULL);
86+
error = ds3_put_object_request(client, request, NULL, NULL);
7487
ds3_request_free(request);
88+
ds3_master_object_list_response_free(bulk_response);
7589
handle_error(error);
7690

7791
ds3_list_bucket_result_response* response;

0 commit comments

Comments
 (0)