diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2021-09-10 18:15:48 +0200 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2021-09-10 19:58:07 +0200 |
commit | 51269c4d28c04ebd2c0047772b7373e0bebec219 (patch) | |
tree | 39795b7bd07ae176bc42fe3444b3ea625eb0663c /connectivity/source | |
parent | c42eb3d3f6c8be0bb8d3d4c6955d13279c0dbcc1 (diff) |
tdf#115547: Fix DB path handling
1. The code used wrong procedure to convert file URLs to local paths.
It assumed that it's enough to just strip the leading 'file://', which
is only sometimes true on Unix-like systems; on Windows, this converts
a valid 'file:///C:/path/file.ext' to '/C:/path/file.ext', where the
leading slash is then treated as a network path, resulting in errors.
2. It is incorrect to assume the same length for UTF-16 and UTF-8
encoded URLs coming from untrusted source (like user file). It may
contain non-ASCII characters (be an IRL), and then the assumption
would fail.
Change-Id: Ie2ea6c8cb9a690975db956fa025bf926a8010984
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121885
Reviewed-by: Lionel Mamane <lionel@mamane.lu>
Tested-by: Jenkins
Diffstat (limited to 'connectivity/source')
-rw-r--r-- | connectivity/source/drivers/firebird/Connection.cxx | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/connectivity/source/drivers/firebird/Connection.cxx b/connectivity/source/drivers/firebird/Connection.cxx index 6c150fe2fb8f..eb0c100b0fc1 100644 --- a/connectivity/source/drivers/firebird/Connection.cxx +++ b/connectivity/source/drivers/firebird/Connection.cxx @@ -49,6 +49,7 @@ #include <unotools/tempfile.hxx> #include <unotools/localfilehelper.hxx> +#include <osl/file.hxx> #include <rtl/strbuf.hxx> #include <sal/log.hxx> @@ -205,7 +206,7 @@ void Connection::construct(const OUString& url, const Sequence< PropertyValue >& if (!xFileAccess->exists(m_sFirebirdURL)) bIsNewDatabase = true; - m_sFirebirdURL = m_sFirebirdURL.copy(OUString("file://").getLength()); + osl::FileBase::getSystemPathFromFileURL(m_sFirebirdURL, m_sFirebirdURL); } } @@ -274,11 +275,12 @@ void Connection::construct(const OUString& url, const Sequence< PropertyValue >& ISC_STATUS_ARRAY status; /* status vector */ ISC_STATUS aErr; + const OString sFirebirdURL = OUStringToOString(m_sFirebirdURL, RTL_TEXTENCODING_UTF8); if (bIsNewDatabase) { aErr = isc_create_database(status, - m_sFirebirdURL.getLength(), - OUStringToOString(m_sFirebirdURL,RTL_TEXTENCODING_UTF8).getStr(), + sFirebirdURL.getLength(), + sFirebirdURL.getStr(), &m_aDBHandle, dpbBuffer.size(), dpbBuffer.c_str(), @@ -296,8 +298,8 @@ void Connection::construct(const OUString& url, const Sequence< PropertyValue >& } aErr = isc_attach_database(status, - m_sFirebirdURL.getLength(), - OUStringToOString(m_sFirebirdURL, RTL_TEXTENCODING_UTF8).getStr(), + sFirebirdURL.getLength(), + sFirebirdURL.getStr(), &m_aDBHandle, dpbBuffer.size(), dpbBuffer.c_str()); |