connectivity/source/drivers/firebird/Connection.cxx |   12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

New commits:
commit e4a87773d0f6a4a4eb8605cf8c3eb6c1cc8e7c27
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Fri Sep 10 18:15:48 2021 +0200
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Mon Sep 13 18:04:58 2021 +0200

    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 <lio...@mamane.lu>
    Tested-by: Jenkins
    (cherry picked from commit 51269c4d28c04ebd2c0047772b7373e0bebec219)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121983
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>
    (cherry picked from commit 9601ca71b485bba6221e1e0ab88accf3e89a325b)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121991

diff --git a/connectivity/source/drivers/firebird/Connection.cxx 
b/connectivity/source/drivers/firebird/Connection.cxx
index 05c24e9f73be..371f24498212 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>
 
@@ -208,7 +209,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);
             }
         }
 
@@ -263,11 +264,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(),
@@ -285,8 +287,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());

Reply via email to