Skip to content

Commit 0511671

Browse files
authored
Merge pull request #5648 from percona-ysorokin/dev/PS-9823-8.0-mysql_migrate_keyring_unusable
PS-9823 fix: mysql_migrate_keyring won't work with PS's components (8.0)
2 parents 3388c2a + b598edd commit 0511671

File tree

31 files changed

+444
-171
lines changed

31 files changed

+444
-171
lines changed

components/keyrings/common/CMakeLists.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ SET(KEYRING_COMMON_SOURCES
3030
# Data representation
3131
data/data.cc
3232
data/meta.cc
33-
data/pfs_string.cpp
3433
# File reader/writer
3534
data_file/reader.cc
3635
data_file/writer.cc
@@ -51,10 +50,6 @@ IF(COMPONENT_COMPILE_VISIBILITY)
5150
SET(COMPILE_OPTIONS_ARG COMPILE_OPTIONS "${COMPONENT_COMPILE_VISIBILITY}")
5251
ENDIF()
5352

54-
INCLUDE_DIRECTORIES(SYSTEM
55-
${BOOST_PATCHES_DIR}
56-
${BOOST_INCLUDE_DIR})
57-
5853
ADD_CONVENIENCE_LIBRARY(
5954
keyring_common
6055
${KEYRING_COMMON_SOURCES}

components/keyrings/common/data/pfs_string.cpp

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 2 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,8 @@
1-
21
#ifndef PFS_STRING_INCLUDED
32
#define PFS_STRING_INCLUDED
43

5-
#include <limits>
6-
#include "my_sys.h"
7-
#include "mysql/service_mysql_alloc.h"
8-
#include "sql/psi_memory_key.h"
9-
10-
extern PSI_memory_key KEY_mem_keyring;
11-
12-
/**
13-
Malloc_allocator is based on sql/malloc_allocator.h, but uses a fixed PSI key
14-
instead
15-
*/
16-
template <class T = void *>
17-
class Malloc_allocator {
18-
// This cannot be const if we want to be able to swap.
19-
PSI_memory_key m_key = KEY_mem_keyring;
20-
21-
public:
22-
typedef T value_type;
23-
typedef size_t size_type;
24-
typedef ptrdiff_t difference_type;
25-
26-
typedef T *pointer;
27-
typedef const T *const_pointer;
28-
29-
typedef T &reference;
30-
typedef const T &const_reference;
31-
32-
pointer address(reference r) const { return &r; }
33-
const_pointer address(const_reference r) const { return &r; }
34-
35-
explicit Malloc_allocator() {}
36-
37-
template <class U>
38-
Malloc_allocator(const Malloc_allocator<U> &other [[maybe_unused]])
39-
: m_key(other.psi_key()) {}
40-
41-
template <class U>
42-
Malloc_allocator &operator=(const Malloc_allocator<U> &other
43-
[[maybe_unused]]) {
44-
assert(m_key == other.psi_key()); // Don't swap key.
45-
}
46-
47-
pointer allocate(size_type n, const_pointer hint [[maybe_unused]] = nullptr) {
48-
if (n == 0) return nullptr;
49-
if (n > max_size()) throw std::bad_alloc();
50-
51-
pointer p = static_cast<pointer>(
52-
my_malloc(m_key, n * sizeof(T), MYF(MY_WME | ME_FATALERROR)));
53-
if (p == nullptr) throw std::bad_alloc();
54-
return p;
55-
}
56-
57-
void deallocate(pointer p, size_type) { my_free(p); }
58-
59-
template <class U, class... Args>
60-
void construct(U *p, Args &&... args) {
61-
assert(p != nullptr);
62-
try {
63-
::new ((void *)p) U(std::forward<Args>(args)...);
64-
} catch (...) {
65-
assert(false); // Constructor should not throw an exception.
66-
}
67-
}
68-
69-
void destroy(pointer p) {
70-
assert(p != nullptr);
71-
try {
72-
p->~T();
73-
} catch (...) {
74-
assert(false); // Destructor should not throw an exception
75-
}
76-
}
77-
78-
size_type max_size() const {
79-
return std::numeric_limits<size_t>::max() / sizeof(T);
80-
}
81-
82-
template <class U>
83-
struct rebind {
84-
typedef Malloc_allocator<U> other;
85-
};
86-
87-
PSI_memory_key psi_key() const { return m_key; }
88-
};
89-
90-
template <class T>
91-
bool operator==(const Malloc_allocator<T> &a1, const Malloc_allocator<T> &a2) {
92-
return a1.psi_key() == a2.psi_key();
93-
}
94-
95-
template <class T>
96-
bool operator!=(const Malloc_allocator<T> &a1, const Malloc_allocator<T> &a2) {
97-
return a1.psi_key() != a2.psi_key();
98-
}
4+
#include <string>
995

100-
using pfs_string =
101-
std::basic_string<char, std::char_traits<char>, Malloc_allocator<char>>;
6+
using pfs_string = std::string;
1027

1038
#endif // PFS_STRING_INCLUDED

components/keyrings/keyring_file/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ MYSQL_ADD_COMPONENT(keyring_file
8484
LINK_LIBRARIES ${KEYRING_FILE_LIBRARIES}
8585
MODULE_ONLY
8686
)
87+
88+
MY_TARGET_LINK_OPTIONS(component_keyring_file "${LINK_FLAG_NO_UNDEFINED}")
89+
8790
IF(APPLE)
8891
SET_TARGET_PROPERTIES(component_keyring_file PROPERTIES
8992
LINK_FLAGS "-undefined dynamic_lookup")

components/keyrings/keyring_kmip/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ MYSQL_ADD_COMPONENT(keyring_kmip
8383
LINK_LIBRARIES ${KEYRING_KMIP_LIBRARIES}
8484
MODULE_ONLY
8585
)
86+
87+
MY_TARGET_LINK_OPTIONS(component_keyring_kmip "${LINK_FLAG_NO_UNDEFINED}")
88+
8689
IF(APPLE)
8790
SET_TARGET_PROPERTIES(component_keyring_kmip PROPERTIES
8891
LINK_FLAGS "-undefined dynamic_lookup")

components/keyrings/keyring_kmip/backend/backend.cc

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include <memory>
2626

2727
#include "backend.h"
28-
#include "my_dbug.h"
2928

3029
#include <mysql/components/minimal_chassis.h>
3130

@@ -47,15 +46,13 @@ using keyring_common::utils::get_random_data;
4746

4847
Keyring_kmip_backend::Keyring_kmip_backend(config::Config_pod const &config)
4948
: valid_(false), config_(config) {
50-
DBUG_TRACE;
5149
valid_ = true;
5250
}
5351

5452
bool Keyring_kmip_backend::load_cache(
5553
keyring_common::operations::Keyring_operations<
5654
Keyring_kmip_backend, keyring_common::data::Data_extension<IdExt>>
5755
&operations) {
58-
DBUG_TRACE;
5956
// We have to load keys and secrets with state==ACTIVE only
6057
//TODO: implement better logic with the new KMIP library
6158
try {
@@ -126,9 +123,16 @@ bool Keyring_kmip_backend::load_cache(
126123
return true;
127124
}
128125
}
129-
126+
} catch (const std::exception &e) {
127+
std::string err_msg = std::string("std exception in function '") +
128+
__func__ + "': " + e.what();
129+
LogComponentErr(ERROR_LEVEL, ER_LOG_PRINTF_MSG, err_msg.c_str());
130+
return true;
130131
} catch (...) {
131-
mysql_components_handle_std_exception(__func__);
132+
std::string err_msg =
133+
std::string("Unknown exception in function '") + __func__ + '\'';
134+
LogComponentErr(ERROR_LEVEL, ER_LOG_PRINTF_MSG, err_msg.c_str());
135+
return true;
132136
}
133137

134138
return false;
@@ -137,13 +141,11 @@ bool Keyring_kmip_backend::load_cache(
137141
bool Keyring_kmip_backend::get(const Metadata &, Data &) const {
138142
/* Shouldn't have reached here if we cache things. */
139143
assert(0);
140-
DBUG_TRACE;
141144
return false;
142145
}
143146

144147
bool Keyring_kmip_backend::store(const Metadata &metadata,
145148
Data_extension<IdExt> &data) {
146-
DBUG_TRACE;
147149
if (!metadata.valid() || !data.valid()) return true;
148150
kmippp::context::id_t id;
149151
try {
@@ -184,8 +186,15 @@ bool Keyring_kmip_backend::store(const Metadata &metadata,
184186
return true;
185187
}
186188
data.set_extension({id});
189+
} catch (const std::exception &e) {
190+
std::string err_msg = std::string("std exception in function '") +
191+
__func__ + "': " + e.what();
192+
LogComponentErr(ERROR_LEVEL, ER_LOG_PRINTF_MSG, err_msg.c_str());
193+
return true;
187194
} catch (...) {
188-
mysql_components_handle_std_exception(__func__);
195+
std::string err_msg =
196+
std::string("Unknown exception in function '") + __func__ + '\'';
197+
LogComponentErr(ERROR_LEVEL, ER_LOG_PRINTF_MSG, err_msg.c_str());
189198
return true;
190199
}
191200
return false;
@@ -204,15 +213,21 @@ size_t Keyring_kmip_backend::size() const {
204213
return keys.size() + secrets.size();
205214
//we may have deactivated keys counted, so we need to count active keys only
206215
//TODO: implement better logic with the new KMIP library
216+
} catch (const std::exception &e) {
217+
std::string err_msg = std::string("std exception in function '") +
218+
__func__ + "': " + e.what();
219+
LogComponentErr(ERROR_LEVEL, ER_LOG_PRINTF_MSG, err_msg.c_str());
220+
return 0;
207221
} catch (...) {
208-
mysql_components_handle_std_exception(__func__);
222+
std::string err_msg =
223+
std::string("Unknown exception in function '") + __func__ + '\'';
224+
LogComponentErr(ERROR_LEVEL, ER_LOG_PRINTF_MSG, err_msg.c_str());
209225
return 0;
210226
}
211227
}
212228

213229
bool Keyring_kmip_backend::erase(const Metadata &metadata,
214230
Data_extension<IdExt> &data) {
215-
DBUG_TRACE;
216231
if (!metadata.valid()) return true;
217232

218233
auto ctx = kmip_ctx();
@@ -238,7 +253,6 @@ bool Keyring_kmip_backend::erase(const Metadata &metadata,
238253
bool Keyring_kmip_backend::generate(const Metadata &metadata,
239254
Data_extension<IdExt> &data,
240255
size_t length) {
241-
DBUG_TRACE;
242256
if (!metadata.valid()) return true;
243257

244258
std::unique_ptr<unsigned char[]> key(new unsigned char[length]);

components/keyrings/keyring_kmip/keyring_kmip.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,6 @@ PROVIDES_SERVICE(component_keyring_kmip, keyring_aes),
218218
PROVIDES_SERVICE(component_keyring_kmip, log_builtins_string),
219219
END_COMPONENT_PROVIDES();
220220

221-
PSI_memory_key KEY_mem_keyring_kmip;
222-
223221
/** List of dependencies */
224222
BEGIN_COMPONENT_REQUIRES(component_keyring_kmip)
225223
REQUIRES_SERVICE(registry), REQUIRES_SERVICE(log_builtins),

components/keyrings/keyring_kms/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ SET(KEYRING_KMS_LIBRARIES keyring_common ext::curl ${SSL_LIBRARIES})
7373

7474
MYSQL_ADD_COMPONENT(keyring_kms ${KEYRING_KMS_SOURCE} LINK_LIBRARIES ${KEYRING_KMS_LIBRARIES} MODULE_ONLY)
7575

76+
MY_TARGET_LINK_OPTIONS(component_keyring_kms "${LINK_FLAG_NO_UNDEFINED}")
77+
7678
MY_CHECK_CXX_COMPILER_WARNING("-Wno-suggest-override" HAS_FLAG)
7779
IF(HAS_FLAG)
7880
TARGET_COMPILE_OPTIONS(component_keyring_kms PUBLIC "-Wno-suggest-override")

components/test/keyring_encryption_test/options.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
#include <my_inttypes.h> /* typedefs */
3535
#include <my_macros.h> /* STRINGIFY_ARG */
3636
#include <mysql.h> /* MYSQL */
37-
#include <mysql/service_mysql_alloc.h>/* my_strdup */
3837
#include <mysql_com.h> /* get_tty_password */
3938
#include <print_version.h> /* print_version */
4039
#include <typelib.h> /* find_type_or_exit */

include/my_sys.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -612,9 +612,7 @@ extern size_t my_fwrite(FILE *stream, const uchar *Buffer, size_t Count,
612612
myf MyFlags);
613613
extern my_off_t my_fseek(FILE *stream, my_off_t pos, int whence);
614614
extern my_off_t my_ftell(FILE *stream);
615-
#if !defined(HAVE_MEMSET_S)
616-
void memset_s(void *dest, size_t dest_max, int c, size_t n);
617-
#endif
615+
void my_memset_s(void *dest, size_t dest_max, int c, size_t n);
618616

619617
/* implemented in my_syslog.c */
620618

0 commit comments

Comments
 (0)