Skip to content

Commit 5a8e7b9

Browse files
committed
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3: Fix bug #76809 (SSL settings aren't respected when persistent connection is reused)
2 parents de83036 + f4d078b commit 5a8e7b9

File tree

2 files changed

+86
-5
lines changed

2 files changed

+86
-5
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ PHP NEWS
66
. Fixed bug #77335 (PHP is preventing SIGALRM from specifying SA_RESTART).
77
(Nikita)
88

9+
- MySQLi:
10+
. Fixed bug #76809 (SSL settings aren't respected when persistent connections
11+
are used). (fabiomsouto)
12+
913
- SimpleXML:
1014
. Fixed bug #75245 (Don't set content of elements with only whitespaces).
1115
(eriklundin)

ext/mysqli/mysqli_nonapi.c

Lines changed: 82 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,13 @@ void mysqli_common_connect(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_real_conne
5454
MY_MYSQL *mysql = NULL;
5555
MYSQLI_RESOURCE *mysqli_resource = NULL;
5656
zval *object = getThis();
57-
char *hostname = NULL, *username=NULL, *passwd=NULL, *dbname=NULL, *socket=NULL;
58-
size_t hostname_len = 0, username_len = 0, passwd_len = 0, dbname_len = 0, socket_len = 0;
59-
zend_bool persistent = FALSE;
60-
zend_long port = 0, flags = 0;
61-
zend_bool port_is_null = 1;
57+
char *hostname = NULL, *username=NULL, *passwd=NULL, *dbname=NULL, *socket=NULL,
58+
*ssl_key = NULL, *ssl_cert = NULL, *ssl_ca = NULL, *ssl_capath = NULL,
59+
*ssl_cipher = NULL;
60+
size_t hostname_len = 0, username_len = 0, passwd_len = 0, dbname_len = 0, socket_len = 0;
61+
zend_bool persistent = FALSE, ssl = FALSE;
62+
zend_long port = 0, flags = 0;
63+
zend_bool port_is_null = 1;
6264
zend_string *hash_key = NULL;
6365
zend_bool new_connection = FALSE;
6466
zend_resource *le;
@@ -188,6 +190,33 @@ void mysqli_common_connect(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_real_conne
188190

189191
goto end;
190192
} else {
193+
#ifdef MYSQLI_USE_MYSQLND
194+
if (mysql->mysql->data->vio->data->ssl) {
195+
/* copy over pre-existing ssl settings so we can reuse them when reconnecting */
196+
ssl = TRUE;
197+
198+
ssl_key = mysql->mysql->data->vio->data->options.ssl_key ? estrdup(mysql->mysql->data->vio->data->options.ssl_key) : NULL;
199+
ssl_cert = mysql->mysql->data->vio->data->options.ssl_cert ? estrdup(mysql->mysql->data->vio->data->options.ssl_cert) : NULL;
200+
ssl_ca = mysql->mysql->data->vio->data->options.ssl_ca ? estrdup(mysql->mysql->data->vio->data->options.ssl_ca) : NULL;
201+
ssl_capath = mysql->mysql->data->vio->data->options.ssl_capath ? estrdup(mysql->mysql->data->vio->data->options.ssl_capath) : NULL;
202+
ssl_cipher = mysql->mysql->data->vio->data->options.ssl_cipher ? estrdup(mysql->mysql->data->vio->data->options.ssl_cipher) : NULL;
203+
}
204+
#else
205+
if (mysql->mysql->options.ssl_key
206+
|| mysql->mysql->options.ssl_cert
207+
|| mysql->mysql->options.ssl_ca
208+
|| mysql->mysql->options.ssl_capath
209+
|| mysql->mysql->options.ssl_cipher) {
210+
/* copy over pre-existing ssl settings so we can reuse them when reconnecting */
211+
ssl = TRUE;
212+
213+
ssl_key = mysql->mysql->options.ssl_key ? estrdup(mysql->mysql->options.ssl_key) : NULL;
214+
ssl_cert = mysql->mysql->options.ssl_cert ? estrdup(mysql->mysql->options.ssl_cert) : NULL;
215+
ssl_ca = mysql->mysql->options.ssl_ca ? estrdup(mysql->mysql->options.ssl_ca) : NULL;
216+
ssl_capath = mysql->mysql->options.ssl_capath ? estrdup(mysql->mysql->options.ssl_capath) : NULL;
217+
ssl_cipher = mysql->mysql->options.ssl_cipher ? estrdup(mysql->mysql->options.ssl_cipher) : NULL;
218+
}
219+
#endif
191220
mysqli_close(mysql->mysql, MYSQLI_CLOSE_IMPLICIT);
192221
mysql->mysql = NULL;
193222
}
@@ -229,8 +258,56 @@ void mysqli_common_connect(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_real_conne
229258
/* BC for prior to bug fix #53425 */
230259
flags |= CLIENT_MULTI_RESULTS;
231260

261+
if (ssl) {
262+
/* if we're here, this means previous conn was ssl, repopulate settings */
263+
mysql_ssl_set(mysql->mysql, ssl_key, ssl_cert, ssl_ca, ssl_capath, ssl_cipher);
264+
265+
if (ssl_key) {
266+
efree(ssl_key);
267+
}
268+
269+
if (ssl_cert) {
270+
efree(ssl_cert);
271+
}
272+
273+
if (ssl_ca) {
274+
efree(ssl_ca);
275+
}
276+
277+
if (ssl_capath) {
278+
efree(ssl_capath);
279+
}
280+
281+
if (ssl_cipher) {
282+
efree(ssl_cipher);
283+
}
284+
}
232285
if (mysql_real_connect(mysql->mysql, hostname, username, passwd, dbname, port, socket, flags) == NULL)
233286
#else
287+
if (ssl) {
288+
/* if we're here, this means previous conn was ssl, repopulate settings */
289+
mysql_ssl_set(mysql->mysql, ssl_key, ssl_cert, ssl_ca, ssl_capath, ssl_cipher);
290+
291+
if (ssl_key) {
292+
efree(ssl_key);
293+
}
294+
295+
if (ssl_cert) {
296+
efree(ssl_cert);
297+
}
298+
299+
if (ssl_ca) {
300+
efree(ssl_ca);
301+
}
302+
303+
if (ssl_capath) {
304+
efree(ssl_capath);
305+
}
306+
307+
if (ssl_cipher) {
308+
efree(ssl_cipher);
309+
}
310+
}
234311
if (mysqlnd_connect(mysql->mysql, hostname, username, passwd, passwd_len, dbname, dbname_len,
235312
port, socket, flags, MYSQLND_CLIENT_KNOWS_RSET_COPY_DATA) == NULL)
236313
#endif

0 commit comments

Comments
 (0)