Skip to content

Commit bea035a

Browse files
committed
- Unittests: link static library instead of dynamic
- TLS/SSL: renamed HAVE_SSL to HAVE_TLS to avoid trouble in 10.2-integration - Fixed wrong timeout in non-blocking mode - Fixed valgrind error in prepared statement
1 parent 2004962 commit bea035a

18 files changed

+89
-139
lines changed

CMakeLists.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ IF(NOT WITH_SSL STREQUAL "OFF")
206206
IF(WITH_SSL STREQUAL "OPENSSL")
207207
FIND_PACKAGE(OpenSSL)
208208
IF(OPENSSL_FOUND)
209-
ADD_DEFINITIONS(-DHAVE_OPENSSL -DHAVE_SSL)
209+
ADD_DEFINITIONS(-DHAVE_OPENSSL -DHAVE_TLS)
210210
SET(SSL_SOURCES "${CMAKE_SOURCE_DIR}/libmariadb/secure/openssl.c")
211211
SET(SSL_LIBRARIES ${OPENSSL_LIBRARIES} ${OPENSSL_CRYPTO_LIBRARIES})
212212
INCLUDE_DIRECTORIES(BEFORE ${OPENSSL_INCLUDE_DIR})
@@ -218,7 +218,7 @@ IF(NOT WITH_SSL STREQUAL "OFF")
218218
IF(WITH_SSL STREQUAL "GNUTLS")
219219
FIND_PACKAGE(GnuTLS)
220220
IF(GNUTLS_FOUND)
221-
ADD_DEFINITIONS(-DHAVE_GNUTLS -DHAVE_SSL)
221+
ADD_DEFINITIONS(-DHAVE_GNUTLS -DHAVE_TLS)
222222
SET(SSL_SOURCES "${CMAKE_SOURCE_DIR}/libmariadb/secure/gnutls.c")
223223
SET(SSL_LIBRARIES ${GNUTLS_LIBRARY})
224224
ELSE()
@@ -227,7 +227,7 @@ IF(NOT WITH_SSL STREQUAL "OFF")
227227
ENDIF()
228228
IF(WIN32)
229229
IF(WITH_SSL STREQUAL "SCHANNEL")
230-
ADD_DEFINITIONS(-DHAVE_SCHANNEL -DHAVE_SSL)
230+
ADD_DEFINITIONS(-DHAVE_SCHANNEL -DHAVE_TLS)
231231
SET(SSL_SOURCES "${CMAKE_SOURCE_DIR}/libmariadb/secure/schannel.c" "${CMAKE_SOURCE_DIR}/libmariadb/secure/ma_schannel.c")
232232
INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/plugins/pvio/")
233233
ENDIF()

include/ma_pvio.h

+1-9
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define _ma_pvio_h_
33
#define cio_defined
44

5-
#ifdef HAVE_SSL
5+
#ifdef HAVE_TLS
66
#include <ma_tls.h>
77
#else
88
#define MARIADB_TLS void
@@ -18,7 +18,6 @@
1818
struct st_ma_pvio_methods;
1919
typedef struct st_ma_pvio_methods PVIO_METHODS;
2020

21-
#ifdef HAVE_NONBLOCK
2221
#define IS_PVIO_ASYNC(a) \
2322
((a)->mysql && (a)->mysql->options.extension && (a)->mysql->options.extension->async_context)
2423

@@ -30,12 +29,6 @@ typedef struct st_ma_pvio_methods PVIO_METHODS;
3029

3130
#define IS_MYSQL_ASYNC_ACTIVE(a) \
3231
(IS_MYSQL_ASYNC(a)&& (a)->options.extension->async_context->active)
33-
#else
34-
#define IS_PVIO_ASYNC(a) (0)
35-
#define IS_PVIO_ASYNC_ACTIVE(a) (0)
36-
#define IS_MYSQL_ASYNC(a) (0)
37-
#define IS_MYSQL_ASYNC_ACTIVE(a) (0)
38-
#endif
3932

4033
enum enum_pvio_timeout {
4134
PVIO_CONNECT_TIMEOUT= 0,
@@ -80,7 +73,6 @@ struct st_ma_pvio {
8073
int ssl_type; /* todo: change to enum (ssl plugins) */
8174
MARIADB_TLS *ctls;
8275
MYSQL *mysql;
83-
struct mysql_async_context *async_context; /* For non-blocking API */
8476
PVIO_METHODS *methods;
8577
void (*set_error)(MYSQL *mysql, unsigned int error_nr, const char *sqlstate, const char *format, ...);
8678
void (*callback)(MARIADB_PVIO *pvio, my_bool is_read, const char *buffer, size_t length);

include/mariadb_async.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ extern ssize_t my_send_async(MARIADB_PVIO *pvio,
2828
int timeout);
2929
extern my_bool my_io_wait_async(struct mysql_async_context *b,
3030
enum enum_pvio_io_event event, int timeout);
31-
#ifdef HAVE_SSL
31+
#ifdef HAVE_TLS
3232
extern int my_ssl_read_async(struct mysql_async_context *b, MARIADB_TLS *tls,
3333
void *buf, int size);
3434
extern int my_ssl_write_async(struct mysql_async_context *b, MARIADB_TLS *tls,

libmariadb/ma_pvio.c

+6-18
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,8 @@
5151
#include <string.h>
5252
#include <ma_common.h>
5353
#include <ma_pvio.h>
54-
#ifdef HAVE_NONBLOCK
5554
#include <mariadb_async.h>
5655
#include <ma_context.h>
57-
#endif
5856

5957
/* callback functions for read/write */
6058
LIST *pvio_callback= NULL;
@@ -121,6 +119,8 @@ MARIADB_PVIO *ma_pvio_init(MA_PVIO_CINFO *cinfo)
121119
if (pvio->methods->set_timeout)
122120
{
123121
pvio->methods->set_timeout(pvio, PVIO_CONNECT_TIMEOUT, cinfo->mysql->options.connect_timeout);
122+
pvio->methods->set_timeout(pvio, PVIO_READ_TIMEOUT, cinfo->mysql->options.connect_timeout);
123+
pvio->methods->set_timeout(pvio, PVIO_WRITE_TIMEOUT, cinfo->mysql->options.connect_timeout);
124124
}
125125

126126
if (!(pvio->cache= calloc(1, PVIO_READ_AHEAD_CACHE_SIZE)))
@@ -177,7 +177,6 @@ my_bool ma_pvio_set_timeout(MARIADB_PVIO *pvio,
177177
}
178178
/* }}} */
179179

180-
#ifdef HAVE_NONBLOCK
181180
/* {{{ size_t ma_pvio_read_async */
182181
static size_t ma_pvio_read_async(MARIADB_PVIO *pvio, uchar *buffer, size_t length)
183182
{
@@ -213,22 +212,19 @@ static size_t ma_pvio_read_async(MARIADB_PVIO *pvio, uchar *buffer, size_t lengt
213212
}
214213
}
215214
/* }}} */
216-
#endif
217215

218216
/* {{{ size_t ma_pvio_read */
219217
size_t ma_pvio_read(MARIADB_PVIO *pvio, uchar *buffer, size_t length)
220218
{
221219
size_t r= -1;
222220
if (!pvio)
223221
return -1;
224-
#ifdef HAVE_NONBLOCK
225222
if (IS_PVIO_ASYNC_ACTIVE(pvio))
226223
{
227224
r= ma_pvio_read_async(pvio, buffer, length);
228225
goto end;
229226
}
230227
else
231-
#endif
232228
{
233229
if (IS_PVIO_ASYNC(pvio))
234230
{
@@ -242,7 +238,7 @@ size_t ma_pvio_read(MARIADB_PVIO *pvio, uchar *buffer, size_t length)
242238
}
243239

244240
/* secure connection */
245-
#ifdef HAVE_SSL
241+
#ifdef HAVE_TLS
246242
if (pvio->ctls)
247243
{
248244
r= ma_pvio_tls_read(pvio->ctls, buffer, length);
@@ -306,7 +302,6 @@ size_t ma_pvio_cache_read(MARIADB_PVIO *pvio, uchar *buffer, size_t length)
306302
}
307303
/* }}} */
308304

309-
#ifdef HAVE_NONBLOCK
310305
/* {{{ size_t ma_pvio_write_async */
311306
static size_t ma_pvio_write_async(MARIADB_PVIO *pvio, const uchar *buffer, size_t length)
312307
{
@@ -336,7 +331,6 @@ static size_t ma_pvio_write_async(MARIADB_PVIO *pvio, const uchar *buffer, size_
336331
}
337332
}
338333
/* }}} */
339-
#endif
340334

341335
/* {{{ size_t ma_pvio_write */
342336
size_t ma_pvio_write(MARIADB_PVIO *pvio, const uchar *buffer, size_t length)
@@ -347,22 +341,20 @@ size_t ma_pvio_write(MARIADB_PVIO *pvio, const uchar *buffer, size_t length)
347341
return -1;
348342

349343
/* secure connection */
350-
#ifdef HAVE_SSL
344+
#ifdef HAVE_TLS
351345
if (pvio->ctls)
352346
{
353347
r= ma_pvio_tls_write(pvio->ctls, buffer, length);
354348
goto end;
355349
}
356350
else
357351
#endif
358-
#ifdef HAVE_NONBLOCK
359352
if (IS_PVIO_ASYNC_ACTIVE(pvio))
360353
{
361354
r= ma_pvio_write_async(pvio, buffer, length);
362355
goto end;
363356
}
364357
else
365-
#endif
366358
{
367359
if (IS_PVIO_ASYNC(pvio))
368360
{
@@ -388,7 +380,7 @@ size_t ma_pvio_write(MARIADB_PVIO *pvio, const uchar *buffer, size_t length)
388380
void ma_pvio_close(MARIADB_PVIO *pvio)
389381
{
390382
/* free internal structures and close connection */
391-
#ifdef HAVE_SSL
383+
#ifdef HAVE_TLS
392384
if (pvio && pvio->ctls)
393385
{
394386
ma_pvio_tls_close(pvio->ctls);
@@ -414,7 +406,6 @@ my_bool ma_pvio_get_handle(MARIADB_PVIO *pvio, void *handle)
414406
}
415407
/* }}} */
416408

417-
#ifdef HAVE_NONBLOCK
418409
/* {{{ ma_pvio_wait_async */
419410
static my_bool
420411
ma_pvio_wait_async(struct mysql_async_context *b, enum enum_pvio_io_event event,
@@ -446,17 +437,14 @@ ma_pvio_wait_async(struct mysql_async_context *b, enum enum_pvio_io_event event,
446437
return (b->events_occured & MYSQL_WAIT_TIMEOUT) ? 0 : 1;
447438
}
448439
/* }}} */
449-
#endif
450440

451441
/* {{{ ma_pvio_wait_io_or_timeout */
452442
int ma_pvio_wait_io_or_timeout(MARIADB_PVIO *pvio, my_bool is_read, int timeout)
453443
{
454-
#ifdef HAVE_NONBLOCK
455444
if (IS_PVIO_ASYNC_ACTIVE(pvio))
456445
return ma_pvio_wait_async(pvio->mysql->options.extension->async_context,
457446
(is_read) ? VIO_IO_EVENT_READ : VIO_IO_EVENT_WRITE,
458447
timeout);
459-
#endif
460448

461449
if (pvio && pvio->methods->wait_io_or_timeout)
462450
return pvio->methods->wait_io_or_timeout(pvio, is_read, timeout);
@@ -504,7 +492,7 @@ my_bool ma_pvio_has_data(MARIADB_PVIO *pvio, ssize_t *data_len)
504492
}
505493
/* }}} */
506494

507-
#ifdef HAVE_SSL
495+
#ifdef HAVE_TLS
508496
/* {{{ my_bool ma_pvio_start_ssl */
509497
my_bool ma_pvio_start_ssl(MARIADB_PVIO *pvio)
510498
{

libmariadb/ma_string.c

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include <ma_string.h>
2828

2929
my_bool ma_init_dynamic_string(DYNAMIC_STRING *str, const char *init_str,
30-
3130
size_t init_alloc, size_t alloc_increment)
3231
{
3332
uint length;

libmariadb/ma_tls.c

+27-27
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* built-in plugin.
3131
*/
3232

33-
#ifdef HAVE_SSL
33+
#ifdef HAVE_TLS
3434

3535
#include <ma_global.h>
3636
#include <ma_sys.h>
@@ -55,68 +55,68 @@ char *ssl_protocol_version[5]= {"unknown", "SSL3", "TLS1.0", "TLS1.1", "TLS1.2"}
5555

5656
MARIADB_TLS *ma_pvio_tls_init(MYSQL *mysql)
5757
{
58-
MARIADB_TLS *cssl= NULL;
58+
MARIADB_TLS *ctls= NULL;
5959

6060
if (!ma_tls_initialized)
6161
ma_tls_start(mysql->net.last_error, MYSQL_ERRMSG_SIZE);
6262

63-
if (!(cssl= (MARIADB_TLS *)calloc(1, sizeof(MARIADB_TLS))))
63+
if (!(ctls= (MARIADB_TLS *)calloc(1, sizeof(MARIADB_TLS))))
6464
{
6565
return NULL;
6666
}
6767

6868
/* register error routine and methods */
69-
cssl->pvio= mysql->net.pvio;
70-
if (!(cssl->ssl= ma_tls_init(mysql)))
69+
ctls->pvio= mysql->net.pvio;
70+
if (!(ctls->ssl= ma_tls_init(mysql)))
7171
{
72-
free(cssl);
73-
cssl= NULL;
72+
free(ctls);
73+
ctls= NULL;
7474
}
75-
return cssl;
75+
return ctls;
7676
}
7777

78-
my_bool ma_pvio_tls_connect(MARIADB_TLS *cssl)
78+
my_bool ma_pvio_tls_connect(MARIADB_TLS *ctls)
7979
{
8080
my_bool rc;
8181

82-
if ((rc= ma_tls_connect(cssl)))
83-
ma_tls_close(cssl);
82+
if ((rc= ma_tls_connect(ctls)))
83+
ma_tls_close(ctls);
8484
return rc;
8585
}
8686

87-
size_t ma_pvio_tls_read(MARIADB_TLS *cssl, const uchar* buffer, size_t length)
87+
size_t ma_pvio_tls_read(MARIADB_TLS *ctls, const uchar* buffer, size_t length)
8888
{
89-
return ma_tls_read(cssl, buffer, length);
89+
return ma_tls_read(ctls, buffer, length);
9090
}
9191

92-
size_t ma_pvio_tls_write(MARIADB_TLS *cssl, const uchar* buffer, size_t length)
92+
size_t ma_pvio_tls_write(MARIADB_TLS *ctls, const uchar* buffer, size_t length)
9393
{
94-
return ma_tls_write(cssl, buffer, length);
94+
return ma_tls_write(ctls, buffer, length);
9595
}
9696

97-
my_bool ma_pvio_tls_close(MARIADB_TLS *cssl)
97+
my_bool ma_pvio_tls_close(MARIADB_TLS *ctls)
9898
{
99-
return ma_tls_close(cssl);
99+
return ma_tls_close(ctls);
100100
}
101101

102-
int ma_pvio_tls_verify_server_cert(MARIADB_TLS *cssl)
102+
int ma_pvio_tls_verify_server_cert(MARIADB_TLS *ctls)
103103
{
104-
return ma_tls_verify_server_cert(cssl);
104+
return ma_tls_verify_server_cert(ctls);
105105
}
106106

107-
const char *ma_pvio_tls_cipher(MARIADB_TLS *cssl)
107+
const char *ma_pvio_tls_cipher(MARIADB_TLS *ctls)
108108
{
109-
return ma_tls_get_cipher(cssl);
109+
return ma_tls_get_cipher(ctls);
110110
}
111111

112112
void ma_pvio_tls_end()
113113
{
114114
ma_tls_end();
115115
}
116116

117-
my_bool ma_pvio_tls_get_protocol_version(MARIADB_TLS *cssl, struct st_ssl_version *version)
117+
my_bool ma_pvio_tls_get_protocol_version(MARIADB_TLS *ctls, struct st_ssl_version *version)
118118
{
119-
return ma_tls_get_protocol_version(cssl, version);
119+
return ma_tls_get_protocol_version(ctls, version);
120120
}
121121

122122
static my_bool ma_pvio_tls_compare_fp(char *fp1, unsigned int fp1_len,
@@ -134,14 +134,14 @@ static my_bool ma_pvio_tls_compare_fp(char *fp1, unsigned int fp1_len,
134134
return 0;
135135
}
136136

137-
my_bool ma_pvio_tls_check_fp(MARIADB_TLS *cssl, const char *fp, const char *fp_list)
137+
my_bool ma_pvio_tls_check_fp(MARIADB_TLS *ctls, const char *fp, const char *fp_list)
138138
{
139139
unsigned int cert_fp_len= 64;
140140
unsigned char cert_fp[64];
141141
my_bool rc=1;
142-
MYSQL *mysql= cssl->pvio->mysql;
142+
MYSQL *mysql= ctls->pvio->mysql;
143143

144-
if ((cert_fp_len= ma_tls_get_finger_print(cssl, cert_fp, cert_fp_len)) < 1)
144+
if ((cert_fp_len= ma_tls_get_finger_print(ctls, cert_fp, cert_fp_len)) < 1)
145145
goto end;
146146
if (fp)
147147
rc= ma_pvio_tls_compare_fp(cert_fp, cert_fp_len, (char *)fp, (unsigned int)strlen(fp));
@@ -186,4 +186,4 @@ my_bool ma_pvio_tls_check_fp(MARIADB_TLS *cssl, const char *fp, const char *fp_l
186186
}
187187
return rc;
188188
}
189-
#endif /* HAVE_SSL */
189+
#endif /* HAVE_TLS */

libmariadb/mariadb_async.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ my_connect_async(MARIADB_PVIO *pvio,
133133
#endif
134134
#endif
135135

136-
#ifdef HAVE_SSL_FIXME
136+
#ifdef HAVE_TLS_FIXME
137137
static my_bool
138138
my_ssl_async_check_result(int res, struct mysql_async_context *b, MARIADB_SSL *cssl)
139139
{

0 commit comments

Comments
 (0)