Skip to content

Commit f4391d4

Browse files
Fixed segmentation fault when attribute value was not set (php#15065)
1 parent 543c4bb commit f4391d4

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

ext/pdo_firebird/firebird_driver.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,15 +1193,15 @@ static int pdo_firebird_get_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val)
11931193
return 1;
11941194

11951195
case PDO_FB_ATTR_DATE_FORMAT:
1196-
ZVAL_STRING(val, H->date_format);
1196+
ZVAL_STRING(val, H->date_format ? H->date_format : PDO_FB_DEF_DATE_FMT);
11971197
return 1;
11981198

11991199
case PDO_FB_ATTR_TIME_FORMAT:
1200-
ZVAL_STRING(val, H->time_format);
1200+
ZVAL_STRING(val, H->time_format ? H->time_format : PDO_FB_DEF_TIME_FMT);
12011201
return 1;
12021202

12031203
case PDO_FB_ATTR_TIMESTAMP_FORMAT:
1204-
ZVAL_STRING(val, H->timestamp_format);
1204+
ZVAL_STRING(val, H->timestamp_format ? H->timestamp_format : PDO_FB_DEF_TIMESTAMP_FMT);
12051205
return 1;
12061206

12071207
case PDO_FB_TRANSACTION_ISOLATION_LEVEL:
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
--TEST--
2+
PDO_Firebird: attr date, time, and timestamp formats
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+
require("testdb.inc");
13+
$dbh = getDbConnection();
14+
15+
echo "== Default state with nothing set. ==\n";
16+
echo 'ATTR_DATE_FORMAT: ', $dbh->getAttribute(Pdo\firebird::ATTR_DATE_FORMAT), "\n";
17+
echo 'ATTR_TIME_FORMAT: ', $dbh->getAttribute(Pdo\firebird::ATTR_TIME_FORMAT), "\n";
18+
echo 'ATTR_TIMESTAMP_FORMAT: ', $dbh->getAttribute(Pdo\firebird::ATTR_TIMESTAMP_FORMAT), "\n";
19+
20+
$dbh->setAttribute(Pdo\firebird::ATTR_DATE_FORMAT, 'Y----m----d');
21+
$dbh->setAttribute(Pdo\firebird::ATTR_TIME_FORMAT, 'H::::i::::s');
22+
$dbh->setAttribute(Pdo\firebird::ATTR_TIMESTAMP_FORMAT, 'Y----m----d....H::::i::::s');
23+
24+
echo "\n";
25+
26+
echo "== State after setting value. ==\n";
27+
echo 'ATTR_DATE_FORMAT: ', $dbh->getAttribute(Pdo\firebird::ATTR_DATE_FORMAT), "\n";
28+
echo 'ATTR_TIME_FORMAT: ', $dbh->getAttribute(Pdo\firebird::ATTR_TIME_FORMAT), "\n";
29+
echo 'ATTR_TIMESTAMP_FORMAT: ', $dbh->getAttribute(Pdo\firebird::ATTR_TIMESTAMP_FORMAT), "\n";
30+
?>
31+
--EXPECT--
32+
== Default state with nothing set. ==
33+
ATTR_DATE_FORMAT: %Y-%m-%d
34+
ATTR_TIME_FORMAT: %H:%M:%S
35+
ATTR_TIMESTAMP_FORMAT: %Y-%m-%d %H:%M:%S
36+
37+
== State after setting value. ==
38+
ATTR_DATE_FORMAT: Y----m----d
39+
ATTR_TIME_FORMAT: H::::i::::s
40+
ATTR_TIMESTAMP_FORMAT: Y----m----d....H::::i::::s

0 commit comments

Comments
 (0)