Skip to content

Commit ea4574b

Browse files
committed
1 parent eaf24ba commit ea4574b

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

ext/pdo/pdo_dbh.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,11 @@ PDO_API void php_pdo_internal_construct_driver(INTERNAL_FUNCTION_PARAMETERS, zen
347347
}
348348

349349
if (!strncmp(data_source, "uri:", sizeof("uri:")-1)) {
350+
zend_error(E_DEPRECATED, "Looking up the DSN from a URI is deprecated due to possible security concerns with DSNs coming from remote URIs");
351+
if (EG(exception)) {
352+
RETURN_THROWS();
353+
}
354+
350355
/* the specified URI holds connection details */
351356
data_source = dsn_from_uri(data_source + sizeof("uri:")-1, alt_dsn, sizeof(alt_dsn));
352357
if (!data_source) {

ext/pdo_mysql/tests/pdo_mysql___construct_uri.phpt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,8 @@ MySQLPDOTest::skip();
6363

6464
print "done!";
6565
?>
66-
--EXPECT--
66+
--EXPECTF--
67+
Deprecated: Looking up the DSN from a URI is deprecated due to possible security concerns with DSNs coming from remote URIs in %s on line %d
68+
69+
Deprecated: Looking up the DSN from a URI is deprecated due to possible security concerns with DSNs coming from remote URIs in %s on line %d
6770
done!
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
--TEST--
2+
PDO_sqlite: PDO->__construct() - URI
3+
--EXTENSIONS--
4+
pdo_sqlite
5+
--FILE--
6+
<?php
7+
$dsnFile = __DIR__ . DIRECTORY_SEPARATOR . "pdo_sqlite___construct_uri.dsn";
8+
$dbFile = __DIR__ . DIRECTORY_SEPARATOR . "pdo_sqlite___construct_uri.db";
9+
file_put_contents($dsnFile, "sqlite:{$dbFile}");
10+
11+
clearstatcache();
12+
var_dump(file_exists($dbFile));
13+
new PDO("uri:{$dsnFile}");
14+
15+
clearstatcache();
16+
var_dump(file_exists($dbFile));
17+
unlink($dbFile);
18+
19+
set_error_handler(function (int $errno, string $errstr, string $errfile, int $errline) {
20+
throw new \ErrorException($errstr, 0, $errno, $errfile, $errline);
21+
});
22+
23+
clearstatcache();
24+
var_dump(file_exists($dbFile));
25+
26+
try {
27+
new PDO("uri:{$dsnFile}");
28+
} catch (Throwable $e) {
29+
echo $e::class, ": ", $e->getMessage(), PHP_EOL;
30+
}
31+
32+
clearstatcache();
33+
var_dump(file_exists($dbFile));
34+
35+
?>
36+
--CLEAN--
37+
<?php
38+
@unlink(__DIR__ . DIRECTORY_SEPARATOR . "pdo_sqlite___construct_uri.dsn");
39+
@unlink(__DIR__ . DIRECTORY_SEPARATOR . "pdo_sqlite___construct_uri.db");
40+
?>
41+
--EXPECTF--
42+
bool(false)
43+
44+
Deprecated: Looking up the DSN from a URI is deprecated due to possible security concerns with DSNs coming from remote URIs in %s on line %d
45+
bool(true)
46+
bool(false)
47+
ErrorException: Looking up the DSN from a URI is deprecated due to possible security concerns with DSNs coming from remote URIs
48+
bool(false)

0 commit comments

Comments
 (0)