diff --git a/ext/pdo_odbc/odbc_driver.c b/ext/pdo_odbc/odbc_driver.c index d84bf66ef9884..7401023c573c7 100644 --- a/ext/pdo_odbc/odbc_driver.c +++ b/ext/pdo_odbc/odbc_driver.c @@ -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) { diff --git a/ext/pdo_pgsql/pgsql_driver.c b/ext/pdo_pgsql/pgsql_driver.c index 1a46cafd8f520..dd3b9535a1626 100644 --- a/ext/pdo_pgsql/pgsql_driver.c +++ b/ext/pdo_pgsql/pgsql_driver.c @@ -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 */