Skip to content

Commit 38deddd

Browse files
committed
Changed to prioritize DSN authentication information over arguments.
Added connection test fixed PR number
1 parent 5a0c007 commit 38deddd

File tree

2 files changed

+80
-2
lines changed

2 files changed

+80
-2
lines changed

ext/pdo_pgsql/pgsql_driver.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,8 +1281,8 @@ static int pdo_pgsql_handle_factory(pdo_dbh_t *dbh, zval *driver_options) /* {{{
12811281
}
12821282

12831283
/* escape username and password, if provided */
1284-
tmp_user = _pdo_pgsql_escape_credentials(dbh->username);
1285-
tmp_pass = _pdo_pgsql_escape_credentials(dbh->password);
1284+
tmp_user = !strstr((char *) dbh->data_source, "user=") ? _pdo_pgsql_escape_credentials(dbh->username) : NULL;
1285+
tmp_pass = !strstr((char *) dbh->data_source, "password=") ? _pdo_pgsql_escape_credentials(dbh->password) : NULL;
12861286

12871287
/* support both full connection string & connection string + login and/or password */
12881288
if (tmp_user && tmp_pass) {

ext/pdo_pgsql/tests/gh12423.phpt

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
--TEST--
2+
GitHub #12424 (Fix GH-12423: [pdo_pgsql] Changed to prioritize DSN authentication information over arguments.)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('pdo') || !extension_loaded('pdo_pgsql')) die('skip not loaded');
6+
require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
7+
require __DIR__ . '/config.inc';
8+
PDOTest::skip();
9+
?>
10+
--FILE--
11+
<?php
12+
require __DIR__ . '/config.inc';
13+
14+
[
15+
'ENV' => [
16+
'PDOTEST_DSN' => $dsnWithCredentials,
17+
'PDOTEST_USER' => $user,
18+
'PDOTEST_PASS' => $password,
19+
],
20+
] = __DIR__ . '/common.phpt';
21+
22+
$dsn = str_replace(" user={$user} password={$password}", '', $dsnWithCredentials);
23+
24+
echo "dsn without credentials / correct user / correct password\n";
25+
try {
26+
$db = new PDO($dsn, $user, $password, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
27+
echo "Connected.\n\n";
28+
} catch (PDOException $e) {
29+
echo $e->getMessage();
30+
}
31+
32+
echo "dsn with credentials / no user / no password\n";
33+
try {
34+
$db = new PDO("{$dsn} user={$user} password={$password}", null, null, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
35+
echo "Connected.\n\n";
36+
} catch (PDOException $e) {
37+
echo $e->getMessage();
38+
}
39+
40+
echo "dsn with correct user / incorrect user / correct password\n";
41+
try {
42+
$db = new PDO("{$dsn} user={$user}", 'hoge', $password, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
43+
echo "Connected.\n\n";
44+
} catch (PDOException $e) {
45+
echo $e->getMessage();
46+
}
47+
48+
echo "dsn with correct password / correct user / incorrect password\n";
49+
try {
50+
$db = new PDO("{$dsn} password={$password}", $user, 'fuga', [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
51+
echo "Connected.\n\n";
52+
} catch (PDOException $e) {
53+
echo $e->getMessage();
54+
}
55+
56+
echo "dsn with correct credentials / incorrect user / incorrect password\n";
57+
try {
58+
$db = new PDO("{$dsn} user={$user} password={$password}", 'hoge', 'fuga', [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
59+
echo "Connected.\n";
60+
} catch (PDOException $e) {
61+
echo $e->getMessage();
62+
}
63+
?>
64+
--EXPECT--
65+
dsn without credentials / correct user / correct password
66+
Connected.
67+
68+
dsn with credentials / no user / no password
69+
Connected.
70+
71+
dsn with correct user / incorrect user / correct password
72+
Connected.
73+
74+
dsn with correct password / correct user / incorrect password
75+
Connected.
76+
77+
dsn with correct credentials / incorrect user / incorrect password
78+
Connected.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy