#43493 [Opn->Csd]: Pdo_pgsql forgets username when given null password
| From: | iliaa@php.net | Date: | Tue, 04 Dec 2007 13:07:33 +0000 |
| Subject: | #43493 [Opn->Csd]: Pdo_pgsql forgets username when given null password | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-120363@lists.php.net to get a copy of this message | ||
ID: 43493
Updated by: iliaa@php.net
Reported By: jurka at ejurka dot com
-Status: Open
+Status: Closed
Bug Type: PDO related
Operating System: Debian Unstable
PHP Version: 5.2.5
New Comment:
This bug has been fixed in CVS.
Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
Thank you for the report, and for helping us make PHP better.
Previous Comments:
------------------------------------------------------------------------
[2007-12-04 10:06:52] jurka at ejurka dot com
Description:
------------
When creating a PDO object using the pgsql driver, the supplied
username is dropped if the password is null.
Reproduce code:
---------------
$pdo = new PDO('pgsql:host=localhost;port=5777;dbname=mydb',
'myuser');
This will not use the "myuser" username supplied. Looking at the code
in ext/pdo_pgsql/pgsql_driver.c circa line 695 it says:
/* support both full connection string & connection string +
login and/or password */
if (!dbh->username || !dbh->password) {
spprintf(&conn_str, 0, "%s connect_timeout=%ld", (char
*) dbh->data_source, connect_timeout);
} else if (dbh->username && dbh->password) {
spprintf(&conn_str, 0, "%s user=%s password=%s
connect_timeout=%ld", dbh->data_source, dbh->username, dbh->password,
connect_timeout);
} else if (dbh->username) {
spprintf(&conn_str, 0, "%s user=%s
connect_timeout=%ld", dbh->data_source, dbh->username,
connect_timeout);
} else {
spprintf(&conn_str, 0, "%s password=%s
connect_timeout=%ld", dbh->data_source, dbh->password,
connect_timeout);
}
It's trying to cover all the cases of username and password set or not,
but the first condition is wrong. It should be
if (!dbh->username && !dbh->password) {
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=43493&edit=1