Skip to content

Commit 8d8f5f7

Browse files
committed
Merge branch 'PHP-8.5'
* PHP-8.5: ext/mysqlnd: Fix persistent free of non-persistent connect_attr key.
2 parents 2f4a214 + 92015ec commit 8d8f5f7

2 files changed

Lines changed: 29 additions & 6 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
mysqli_real_connect() retry on same handle does not corrupt mysqlnd connect_attr
3+
--EXTENSIONS--
4+
mysqli
5+
--SKIPIF--
6+
<?php
7+
require_once 'skipifconnectfailure.inc';
8+
?>
9+
--FILE--
10+
<?php
11+
12+
require 'connect.inc';
13+
14+
$link = mysqli_init();
15+
@mysqli_real_connect($link, $host, $user, 'bogus_password_to_force_failure', $db, $port, $socket);
16+
17+
if (!mysqli_real_connect($link, $host, $user, $passwd, $db, $port, $socket)) {
18+
printf("[001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
19+
}
20+
21+
mysqli_close($link);
22+
23+
print "done!";
24+
?>
25+
--EXPECT--
26+
done!

ext/mysqlnd/mysqlnd_connection.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,17 +1557,14 @@ MYSQLND_METHOD(mysqlnd_conn_data, set_client_option_2d)(MYSQLND_CONN_DATA * cons
15571557
zval attrz;
15581558
zend_string *str;
15591559

1560+
str = zend_string_init(key, strlen(key), conn->persistent);
1561+
ZVAL_NEW_STR(&attrz, zend_string_init(value, strlen(value), conn->persistent));
15601562
if (conn->persistent) {
1561-
str = zend_string_init(key, strlen(key), 1);
15621563
GC_MAKE_PERSISTENT_LOCAL(str);
1563-
ZVAL_NEW_STR(&attrz, zend_string_init(value, strlen(value), 1));
15641564
GC_MAKE_PERSISTENT_LOCAL(Z_COUNTED(attrz));
1565-
} else {
1566-
str = zend_string_init(key, strlen(key), 0);
1567-
ZVAL_NEW_STR(&attrz, zend_string_init(value, strlen(value), 0));
15681565
}
15691566
zend_hash_update(conn->options->connect_attr, str, &attrz);
1570-
zend_string_release_ex(str, 1);
1567+
zend_string_release_ex(str, conn->persistent);
15711568
}
15721569
break;
15731570
default:

0 commit comments

Comments
 (0)