Skip to content

Commit bf19492

Browse files
Daniele SciasciaNirbhay Choubey
authored andcommitted
GCF-837 Check wsrep interface version before loading provider
1 parent dfa9012 commit bf19492

File tree

1 file changed

+31
-6
lines changed

1 file changed

+31
-6
lines changed

wsrep/wsrep_loader.c

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,22 @@ static wsrep_log_cb_t logger = default_logger;
3737
* Library loader
3838
**************************************************************************/
3939

40+
static int wsrep_check_iface_version(const char* found, const char* iface_ver)
41+
{
42+
const size_t msg_len = 128;
43+
char msg[128];
44+
45+
if (strcmp(found, iface_ver)) {
46+
snprintf (msg, msg_len,
47+
"provider interface version mismatch: need '%s', found '%s'",
48+
iface_ver, found);
49+
logger (WSREP_LOG_ERROR, msg);
50+
return EINVAL;
51+
}
52+
53+
return 0;
54+
}
55+
4056
static int verify(const wsrep_t *wh, const char *iface_ver)
4157
{
4258
char msg[128];
@@ -50,13 +66,8 @@ static int verify(const wsrep_t *wh, const char *iface_ver)
5066
VERIFY(wh);
5167
VERIFY(wh->version);
5268

53-
if (strcmp(wh->version, iface_ver)) {
54-
snprintf (msg, sizeof(msg),
55-
"provider interface version mismatch: need '%s', found '%s'",
56-
iface_ver, wh->version);
57-
logger (WSREP_LOG_ERROR, msg);
69+
if (wsrep_check_iface_version(wh->version, iface_ver))
5870
return EINVAL;
59-
}
6071

6172
VERIFY(wh->init);
6273
VERIFY(wh->options_set);
@@ -107,6 +118,15 @@ static wsrep_loader_fun wsrep_dlf(void *dlh, const char *sym)
107118
return alias.dlfun;
108119
}
109120

121+
static int wsrep_check_version_symbol(void *dlh)
122+
{
123+
char** dlversion = NULL;
124+
dlversion = (char**) dlsym(dlh, "wsrep_interface_version");
125+
if (dlversion == NULL)
126+
return 0;
127+
return wsrep_check_iface_version(*dlversion, WSREP_INTERFACE_VERSION);
128+
}
129+
110130
extern int wsrep_dummy_loader(wsrep_t *w);
111131

112132
int wsrep_load(const char *spec, wsrep_t **hptr, wsrep_log_cb_t log_cb)
@@ -151,6 +171,11 @@ int wsrep_load(const char *spec, wsrep_t **hptr, wsrep_log_cb_t log_cb)
151171
goto out;
152172
}
153173

174+
if (wsrep_check_version_symbol(dlh) != 0) {
175+
ret = EINVAL;
176+
goto out;
177+
}
178+
154179
if ((ret = (*dlfun)(*hptr)) != 0) {
155180
snprintf(msg, sizeof(msg), "wsrep_load(): loader failed: %s",
156181
strerror(ret));

0 commit comments

Comments
 (0)