Skip to content

Commit 39dda72

Browse files
authored
ext/mysqli: internal updates (php#19072)
* global struct size reduction. * connection port ini value sanity check addition.
1 parent 3ac2788 commit 39dda72

File tree

3 files changed

+43
-9
lines changed

3 files changed

+43
-9
lines changed

ext/mysqli/mysqli.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,19 @@ static const MYSQLND_REVERSE_API mysqli_reverse_api = {
424424
mysqli_convert_zv_to_mysqlnd
425425
};
426426

427+
static PHP_INI_MH(OnUpdateDefaultPort)
428+
{
429+
zend_long value = ZEND_ATOL(ZSTR_VAL(new_value));
430+
431+
if (value < 0 || value > USHRT_MAX) {
432+
return FAILURE;
433+
}
434+
435+
MyG(default_port) = (unsigned short)value;
436+
437+
return SUCCESS;
438+
}
439+
427440
/* {{{ PHP_INI_BEGIN */
428441
PHP_INI_BEGIN()
429442
STD_PHP_INI_ENTRY_EX("mysqli.max_links", "-1", PHP_INI_SYSTEM, OnUpdateLong, max_links, zend_mysqli_globals, mysqli_globals, display_link_numbers)
@@ -433,7 +446,7 @@ PHP_INI_BEGIN()
433446
STD_PHP_INI_ENTRY("mysqli.default_host", NULL, PHP_INI_ALL, OnUpdateString, default_host, zend_mysqli_globals, mysqli_globals)
434447
STD_PHP_INI_ENTRY("mysqli.default_user", NULL, PHP_INI_ALL, OnUpdateString, default_user, zend_mysqli_globals, mysqli_globals)
435448
STD_PHP_INI_ENTRY("mysqli.default_pw", NULL, PHP_INI_ALL, OnUpdateString, default_pw, zend_mysqli_globals, mysqli_globals)
436-
STD_PHP_INI_ENTRY("mysqli.default_port", "3306", PHP_INI_ALL, OnUpdateLong, default_port, zend_mysqli_globals, mysqli_globals)
449+
STD_PHP_INI_ENTRY("mysqli.default_port", "3306", PHP_INI_ALL, OnUpdateDefaultPort, default_port, zend_mysqli_globals, mysqli_globals)
437450
#ifdef PHP_MYSQL_UNIX_SOCK_ADDR
438451
STD_PHP_INI_ENTRY("mysqli.default_socket", MYSQL_UNIX_ADDR,PHP_INI_ALL,OnUpdateStringUnempty, default_socket, zend_mysqli_globals, mysqli_globals)
439452
#else

ext/mysqli/php_mysqli_structs.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -236,21 +236,21 @@ extern void php_mysqli_fetch_into_hash_aux(zval *return_value, MYSQL_RES * resul
236236

237237

238238
ZEND_BEGIN_MODULE_GLOBALS(mysqli)
239-
zend_long num_links;
240-
zend_long max_links;
241-
zend_long num_active_persistent;
242-
zend_long num_inactive_persistent;
243-
zend_long max_persistent;
239+
unsigned short default_port;
244240
bool allow_persistent;
245-
zend_ulong default_port;
241+
bool allow_local_infile;
246242
char *default_host;
247243
char *default_user;
248244
char *default_pw;
249245
char *default_socket;
250-
bool allow_local_infile;
251246
char *local_infile_directory;
252-
zend_long error_no;
253247
char *error_msg;
248+
zend_long num_links;
249+
zend_long max_links;
250+
zend_long num_active_persistent;
251+
zend_long num_inactive_persistent;
252+
zend_long max_persistent;
253+
zend_long error_no;
254254
zend_long report_mode;
255255
bool rollback_on_cached_plink;
256256
ZEND_END_MODULE_GLOBALS(mysqli)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
default_port ini setting
3+
--EXTENSIONS--
4+
mysqli
5+
--FILE--
6+
<?php
7+
$orig_port = ini_get("mysqli.default_port");
8+
ini_set('mysqli.default_port', 65536);
9+
$new_port = ini_get("mysqli.default_port");
10+
var_dump($orig_port === $new_port);
11+
ini_set('mysqli.default_port', -1);
12+
$new_port = ini_get("mysqli.default_port");
13+
var_dump($orig_port === $new_port);
14+
ini_set('mysqli.default_port', $orig_port - 1);
15+
$new_port = ini_get("mysqli.default_port");
16+
var_dump($orig_port === $new_port);
17+
?>
18+
--EXPECT--
19+
bool(true)
20+
bool(true)
21+
bool(false)

0 commit comments

Comments
 (0)