Skip to content

Fix GH-12423: [pdo_pgsql] Changed to prioritize DSN authentication information over arguments. #12424

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Changed to prioritize DSN authentication information over arguments.
Added connection test

fixed PR number
  • Loading branch information
SakiTakamachi committed Oct 15, 2023
commit 38deddd117251f8e6335efc150facd22211d754f
4 changes: 2 additions & 2 deletions ext/pdo_pgsql/pgsql_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -1281,8 +1281,8 @@ static int pdo_pgsql_handle_factory(pdo_dbh_t *dbh, zval *driver_options) /* {{{
}

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

/* support both full connection string & connection string + login and/or password */
if (tmp_user && tmp_pass) {
Expand Down
78 changes: 78 additions & 0 deletions ext/pdo_pgsql/tests/gh12423.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
--TEST--
GitHub #12424 (Fix GH-12423: [pdo_pgsql] Changed to prioritize DSN authentication information over arguments.)
--SKIPIF--
<?php
if (!extension_loaded('pdo') || !extension_loaded('pdo_pgsql')) die('skip not loaded');
require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
require __DIR__ . '/config.inc';
PDOTest::skip();
?>
--FILE--
<?php
require __DIR__ . '/config.inc';

[
'ENV' => [
'PDOTEST_DSN' => $dsnWithCredentials,
'PDOTEST_USER' => $user,
'PDOTEST_PASS' => $password,
],
] = __DIR__ . '/common.phpt';

$dsn = str_replace(" user={$user} password={$password}", '', $dsnWithCredentials);

echo "dsn without credentials / correct user / correct password\n";
try {
$db = new PDO($dsn, $user, $password, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
echo "Connected.\n\n";
} catch (PDOException $e) {
echo $e->getMessage();
}

echo "dsn with credentials / no user / no password\n";
try {
$db = new PDO("{$dsn} user={$user} password={$password}", null, null, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
echo "Connected.\n\n";
} catch (PDOException $e) {
echo $e->getMessage();
}

echo "dsn with correct user / incorrect user / correct password\n";
try {
$db = new PDO("{$dsn} user={$user}", 'hoge', $password, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
echo "Connected.\n\n";
} catch (PDOException $e) {
echo $e->getMessage();
}

echo "dsn with correct password / correct user / incorrect password\n";
try {
$db = new PDO("{$dsn} password={$password}", $user, 'fuga', [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
echo "Connected.\n\n";
} catch (PDOException $e) {
echo $e->getMessage();
}

echo "dsn with correct credentials / incorrect user / incorrect password\n";
try {
$db = new PDO("{$dsn} user={$user} password={$password}", 'hoge', 'fuga', [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
echo "Connected.\n";
} catch (PDOException $e) {
echo $e->getMessage();
}
?>
--EXPECT--
dsn without credentials / correct user / correct password
Connected.

dsn with credentials / no user / no password
Connected.

dsn with correct user / incorrect user / correct password
Connected.

dsn with correct password / correct user / incorrect password
Connected.

dsn with correct credentials / incorrect user / incorrect password
Connected.
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