Skip to content

Commit 92015ec

Browse files
committed
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4: ext/mysqlnd: Fix persistent free of non-persistent connect_attr key.
2 parents a8f1cef + 6e87107 commit 92015ec

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
@@ -1559,17 +1559,14 @@ MYSQLND_METHOD(mysqlnd_conn_data, set_client_option_2d)(MYSQLND_CONN_DATA * cons
15591559
zval attrz;
15601560
zend_string *str;
15611561

1562+
str = zend_string_init(key, strlen(key), conn->persistent);
1563+
ZVAL_NEW_STR(&attrz, zend_string_init(value, strlen(value), conn->persistent));
15621564
if (conn->persistent) {
1563-
str = zend_string_init(key, strlen(key), 1);
15641565
GC_MAKE_PERSISTENT_LOCAL(str);
1565-
ZVAL_NEW_STR(&attrz, zend_string_init(value, strlen(value), 1));
15661566
GC_MAKE_PERSISTENT_LOCAL(Z_COUNTED(attrz));
1567-
} else {
1568-
str = zend_string_init(key, strlen(key), 0);
1569-
ZVAL_NEW_STR(&attrz, zend_string_init(value, strlen(value), 0));
15701567
}
15711568
zend_hash_update(conn->options->connect_attr, str, &attrz);
1572-
zend_string_release_ex(str, 1);
1569+
zend_string_release_ex(str, conn->persistent);
15731570
}
15741571
break;
15751572
default:

0 commit comments

Comments
 (0)