From: Michael Wallner Date: Mon, 6 Jan 2020 11:35:06 +0000 (+0100) Subject: c++: Fix possible string truncation X-Git-Tag: pre_cmake~83 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=59acef2d2b59a3f1a55337a933b97d901d46133a;p=awesomized%2Flibmemcached c++: Fix possible string truncation --- diff --git a/libtest/has.cc b/libtest/has.cc index 2d9abf6b..0983f070 100644 --- a/libtest/has.cc +++ b/libtest/has.cc @@ -165,7 +165,7 @@ static void initialize_memcached_binary_path() if (access(arg_buffer.str().c_str(), X_OK) == 0) { - strncpy(memcached_binary_path, arg_buffer.str().c_str(), FILENAME_MAX); + strncpy(memcached_binary_path, arg_buffer.str().c_str(), FILENAME_MAX-1); } } #endif diff --git a/libtest/socket.cc b/libtest/socket.cc index 76ac5bf1..9e06841a 100644 --- a/libtest/socket.cc +++ b/libtest/socket.cc @@ -55,7 +55,7 @@ void set_default_socket(const char *socket) { if (socket) { - strncpy(global_socket, socket, strlen(socket)); + strncpy(global_socket, socket, sizeof(global_socket)-1); } } diff --git a/tests/libmemcached-1.0/mem_functions.cc b/tests/libmemcached-1.0/mem_functions.cc index 0e6bcb7f..8b2dc606 100644 --- a/tests/libmemcached-1.0/mem_functions.cc +++ b/tests/libmemcached-1.0/mem_functions.cc @@ -4166,7 +4166,7 @@ test_return_t regression_bug_442914(memcached_st *original_memc) for (uint32_t x= 0; x < 250; ++x) { - char key[250]; + char key[251]; size_t len= (size_t)snprintf(key, sizeof(key), "%0250u", x); memcached_return_t rc= memcached_delete(memc, key, len, 0); char error_buffer[2048]= { 0 }; @@ -4176,7 +4176,7 @@ test_return_t regression_bug_442914(memcached_st *original_memc) // Delete, and then delete again to look for not found { - char key[250]; + char key[251]; size_t len= snprintf(key, sizeof(key), "%037u", 251U); memcached_return_t rc= memcached_delete(memc, key, len, 0); test_true(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED);