Skip to content
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

ext/pdo_{odbc|pgsql}: Use precomputed data_source_len #17744

Merged
merged 2 commits into from
Feb 9, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 7 additions & 7 deletions ext/pdo_odbc/odbc_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -532,14 +532,13 @@ 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*) emalloc(dbh->data_source_len + 1);
devnexen marked this conversation as resolved.
Show resolved Hide resolved
memcpy(db, dbh->data_source, dbh->data_source_len+1);
char *db_end = db + dbh->data_source_len;
db_end--;
if ((unsigned char)*(db_end) == ';') {
*db_end = '\0';
Expand Down Expand Up @@ -593,6 +592,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);
}
Expand All @@ -602,7 +602,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) {
Expand Down
4 changes: 2 additions & 2 deletions ext/pdo_pgsql/pgsql_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ' ';
Expand All @@ -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 */
Expand Down