mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
ext/pdo_{odbc|pgsql}: Use precomputed data_source_len (#17744)
This is already computed by PDO, no need to recompute it again inside the drivers.
This commit is contained in:
committed by
GitHub
parent
4e55889dca
commit
b757fa812d
@@ -532,14 +532,12 @@ static int pdo_odbc_handle_factory(pdo_dbh_t *dbh, zval *driver_options) /* {{{
|
||||
|
||||
use_direct = 1;
|
||||
|
||||
size_t db_len = strlen(dbh->data_source);
|
||||
bool use_uid_arg = dbh->username != NULL && !php_memnistr(dbh->data_source, "uid=", strlen("uid="), dbh->data_source + db_len);
|
||||
bool use_pwd_arg = dbh->password != NULL && !php_memnistr(dbh->data_source, "pwd=", strlen("pwd="), dbh->data_source + db_len);
|
||||
bool use_uid_arg = dbh->username != NULL && !php_memnistr(dbh->data_source, "uid=", strlen("uid="), dbh->data_source + dbh->data_source_len);
|
||||
bool use_pwd_arg = dbh->password != NULL && !php_memnistr(dbh->data_source, "pwd=", strlen("pwd="), dbh->data_source + dbh->data_source_len);
|
||||
|
||||
if (use_uid_arg || use_pwd_arg) {
|
||||
char *db = (char*) emalloc(db_len + 1);
|
||||
strcpy(db, dbh->data_source);
|
||||
char *db_end = db + db_len;
|
||||
char *db = (char*) estrndup(dbh->data_source, dbh->data_source_len);
|
||||
char *db_end = db + dbh->data_source_len;
|
||||
db_end--;
|
||||
if ((unsigned char)*(db_end) == ';') {
|
||||
*db_end = '\0';
|
||||
@@ -593,6 +591,7 @@ static int pdo_odbc_handle_factory(pdo_dbh_t *dbh, zval *driver_options) /* {{{
|
||||
|
||||
pefree((char*)dbh->data_source, dbh->is_persistent);
|
||||
dbh->data_source = dsn;
|
||||
dbh->data_source_len = strlen(dsn);
|
||||
if (uid && should_quote_uid) {
|
||||
efree(uid);
|
||||
}
|
||||
@@ -602,7 +601,7 @@ static int pdo_odbc_handle_factory(pdo_dbh_t *dbh, zval *driver_options) /* {{{
|
||||
efree(db);
|
||||
}
|
||||
|
||||
rc = SQLDriverConnect(H->dbc, NULL, (SQLCHAR *) dbh->data_source, strlen(dbh->data_source),
|
||||
rc = SQLDriverConnect(H->dbc, NULL, (SQLCHAR *) dbh->data_source, dbh->data_source_len,
|
||||
dsnbuf, sizeof(dsnbuf)-1, &dsnbuflen, SQL_DRIVER_NOPROMPT);
|
||||
}
|
||||
if (!use_direct) {
|
||||
|
||||
@@ -1396,7 +1396,7 @@ static int pdo_pgsql_handle_factory(pdo_dbh_t *dbh, zval *driver_options) /* {{{
|
||||
/* PostgreSQL wants params in the connect string to be separated by spaces,
|
||||
* if the PDO standard semicolons are used, we convert them to spaces
|
||||
*/
|
||||
e = (char *) dbh->data_source + strlen(dbh->data_source);
|
||||
e = (char *) dbh->data_source + dbh->data_source_len;
|
||||
p = (char *) dbh->data_source;
|
||||
while ((p = memchr(p, ';', (e - p)))) {
|
||||
*p = ' ';
|
||||
@@ -1410,7 +1410,7 @@ static int pdo_pgsql_handle_factory(pdo_dbh_t *dbh, zval *driver_options) /* {{{
|
||||
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;
|
||||
|
||||
smart_str_appends(&conn_str, dbh->data_source);
|
||||
smart_str_appendl(&conn_str, dbh->data_source, dbh->data_source_len);
|
||||
smart_str_append_printf(&conn_str, " connect_timeout=" ZEND_LONG_FMT, connect_timeout);
|
||||
|
||||
/* support both full connection string & connection string + login and/or password */
|
||||
|
||||
Reference in New Issue
Block a user