Skip to content

Commit bd9f03a

Browse files
committed
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3: Fixed GH-18276 - persistent connection - "zend_mm_heap corrupted" with setAttribute() (#18280) Closes #18280 Fixes #18276
2 parents 691e009 + 9d4f8b5 commit bd9f03a

File tree

3 files changed

+51
-9
lines changed

3 files changed

+51
-9
lines changed

Diff for: NEWS

+4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ PHP NEWS
3939
(nielsdos)
4040
. Fix potential leaks when writing to BIO fails. (nielsdos)
4141

42+
- PDO Firebird:
43+
. Fixed GH-18276 - persistent connection - "zend_mm_heap corrupted"
44+
with setAttribute() (SakiTakamachi).
45+
4246
- SPL:
4347
. Fixed bug GH-18322 (SplObjectStorage debug handler mismanages memory).
4448
(nielsdos)

Diff for: ext/pdo_firebird/firebird_driver.c

+12-9
Original file line numberDiff line numberDiff line change
@@ -599,13 +599,13 @@ static void firebird_handle_closer(pdo_dbh_t *dbh) /* {{{ */
599599
}
600600

601601
if (H->date_format) {
602-
efree(H->date_format);
602+
pefree(H->date_format, dbh->is_persistent);
603603
}
604604
if (H->time_format) {
605-
efree(H->time_format);
605+
pefree(H->time_format, dbh->is_persistent);
606606
}
607607
if (H->timestamp_format) {
608-
efree(H->timestamp_format);
608+
pefree(H->timestamp_format, dbh->is_persistent);
609609
}
610610

611611
if (H->einfo.errmsg) {
@@ -1091,9 +1091,10 @@ static bool pdo_firebird_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val
10911091
return false;
10921092
}
10931093
if (H->date_format) {
1094-
efree(H->date_format);
1094+
pefree(H->date_format, dbh->is_persistent);
1095+
H->date_format = NULL;
10951096
}
1096-
spprintf(&H->date_format, 0, "%s", ZSTR_VAL(str));
1097+
H->date_format = pestrndup(ZSTR_VAL(str), ZSTR_LEN(str),dbh->is_persistent);
10971098
zend_string_release_ex(str, 0);
10981099
}
10991100
return true;
@@ -1105,9 +1106,10 @@ static bool pdo_firebird_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val
11051106
return false;
11061107
}
11071108
if (H->time_format) {
1108-
efree(H->time_format);
1109+
pefree(H->time_format, dbh->is_persistent);
1110+
H->time_format = NULL;
11091111
}
1110-
spprintf(&H->time_format, 0, "%s", ZSTR_VAL(str));
1112+
H->time_format = pestrndup(ZSTR_VAL(str), ZSTR_LEN(str),dbh->is_persistent);
11111113
zend_string_release_ex(str, 0);
11121114
}
11131115
return true;
@@ -1119,9 +1121,10 @@ static bool pdo_firebird_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val
11191121
return false;
11201122
}
11211123
if (H->timestamp_format) {
1122-
efree(H->timestamp_format);
1124+
pefree(H->timestamp_format, dbh->is_persistent);
1125+
H->timestamp_format = NULL;
11231126
}
1124-
spprintf(&H->timestamp_format, 0, "%s", ZSTR_VAL(str));
1127+
H->timestamp_format = pestrndup(ZSTR_VAL(str), ZSTR_LEN(str),dbh->is_persistent);
11251128
zend_string_release_ex(str, 0);
11261129
}
11271130
return true;

Diff for: ext/pdo_firebird/tests/gh18276.phpt

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
--TEST--
2+
GH-18276 (persistent connection - setAttribute(Pdo\Firebird::ATTR_DATE_FORMAT, ..) results in "zend_mm_heap corrupted")
3+
--EXTENSIONS--
4+
pdo_firebird
5+
--SKIPIF--
6+
<?php require('skipif.inc'); ?>
7+
--XLEAK--
8+
A bug in firebird causes a memory leak when calling `isc_attach_database()`.
9+
See https://github.com/FirebirdSQL/firebird/issues/7849
10+
--FILE--
11+
<?php
12+
13+
require("testdb.inc");
14+
unset($dbh);
15+
16+
for ($i = 0; $i < 2; $i++) {
17+
$dbh = new PDO(
18+
PDO_FIREBIRD_TEST_DSN,
19+
PDO_FIREBIRD_TEST_USER,
20+
PDO_FIREBIRD_TEST_PASS,
21+
[
22+
PDO::ATTR_PERSISTENT => true,
23+
],
24+
);
25+
// Avoid interned
26+
$dbh->setAttribute(PDO::FB_ATTR_DATE_FORMAT, str_repeat('Y----m----d', random_int(1, 1)));
27+
$dbh->setAttribute(PDO::FB_ATTR_TIME_FORMAT, str_repeat('H::::i::::s', random_int(1, 1)));
28+
$dbh->setAttribute(PDO::FB_ATTR_TIMESTAMP_FORMAT, str_repeat('Y----m----d....H::::i::::s', random_int(1, 1)));
29+
unset($dbh);
30+
}
31+
32+
echo 'done!';
33+
?>
34+
--EXPECT--
35+
done!

0 commit comments

Comments
 (0)