[Libreoffice-commits] .: Branch 'libreoffice-3-5' - sfx2/source
Bjoern Michaelsen
bmichaelsen at kemper.freedesktop.org
Sat Jun 9 10:45:56 PDT 2012
sfx2/source/dialog/filedlghelper.cxx | 61 ++++++++++++++++++++++++++---------
1 file changed, 47 insertions(+), 14 deletions(-)
New commits:
commit 89f45b9fef98650cc3166d9337c96e58f0c57c4f
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Fri Apr 27 16:54:32 2012 +0200
Related fdo#43895: Fixed shortcommings of FileDialogHelper_Impl::verifyPath
* maPath.reverseCompareToAsciiL("file:///tmp",11) == 0 failed for file:///tmp/
* It was unclear whether special treatment should only happen for files directly
in /tmp or also in sub-dirs; assuming the latter now.
* Proper translation from file URL to system path.
Signed-off-by: Bjoern Michaelsen <bjoern.michaelsen at canonical.com>
diff --git a/sfx2/source/dialog/filedlghelper.cxx b/sfx2/source/dialog/filedlghelper.cxx
index 6acb006..dc07d89 100644
--- a/sfx2/source/dialog/filedlghelper.cxx
+++ b/sfx2/source/dialog/filedlghelper.cxx
@@ -63,6 +63,7 @@
#include <unotools/ucbstreamhelper.hxx>
#include <unotools/ucbhelper.hxx>
#include <unotools/localfilehelper.hxx>
+#include <osl/file.hxx>
#include <osl/mutex.hxx>
#include <osl/security.hxx>
#include <osl/thread.hxx>
@@ -1654,24 +1655,56 @@ void FileDialogHelper_Impl::getRealFilter( String& _rFilter ) const
void FileDialogHelper_Impl::verifyPath()
{
#ifdef UNX
- static char const s_FileScheme[] = "file://";
- if (0 != rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength(
- maPath.getStr(), maPath.getLength(),
- s_FileScheme, RTL_CONSTASCII_LENGTH(s_FileScheme)))
- {
- return;
- }
- const OString sFullPath = OUStringToOString(
- maPath.copy(RTL_CONSTASCII_LENGTH(s_FileScheme)) + maFileName,
- osl_getThreadTextEncoding() );
- struct stat aFileStat;
- stat( sFullPath.getStr(), &aFileStat );
// lp#905355, fdo#43895
// Check that the file has read only permission and is in /tmp -- this is
// the case if we have opened the file from the web with firefox only.
- if ( maPath.reverseCompareToAsciiL("file:///tmp",11) == 0 &&
- ( aFileStat.st_mode & (S_IRWXO + S_IRWXG + S_IRWXU) ) == S_IRUSR )
+ if (maFileName.isEmpty()) {
+ return;
+ }
+ INetURLObject url(maPath);
+ if (url.GetProtocol() != INET_PROT_FILE
+ || url.getName(0, true, INetURLObject::DECODE_WITH_CHARSET) != "tmp")
+ {
+ return;
+ }
+ if (maFileName.indexOf('/') != -1) {
+ SAL_WARN("sfx2", maFileName << " contains /");
+ return;
+ }
+ url.insertName(
+ maFileName, false, INetURLObject::LAST_SEGMENT, true,
+ INetURLObject::ENCODE_ALL);
+ rtl::OUString sysPathU;
+ osl::FileBase::RC e = osl::FileBase::getSystemPathFromFileURL(
+ url.GetMainURL(INetURLObject::NO_DECODE), sysPathU);
+ if (e != osl::FileBase::E_None) {
+ SAL_WARN(
+ "sfx2",
+ "getSystemPathFromFileURL("
+ << url.GetMainURL(INetURLObject::NO_DECODE) << ") failed with "
+ << +e);
+ return;
+ }
+ rtl::OString sysPathC;
+ if (!sysPathU.convertToString(
+ &sysPathC, osl_getThreadTextEncoding(),
+ (RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR
+ | RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR)))
{
+ SAL_WARN(
+ "sfx2",
+ "convertToString(" << sysPathU << ") failed for encoding "
+ << +osl_getThreadTextEncoding());
+ return;
+ }
+ struct stat aFileStat;
+ if (stat(sysPathC.getStr(), &aFileStat) == -1) {
+ SAL_WARN(
+ "sfx2",
+ "stat(" << sysPathC.getStr() << ") failed with errno " << errno);
+ return;
+ }
+ if ((aFileStat.st_mode & (S_IRWXO | S_IRWXG | S_IRWXU)) == S_IRUSR) {
maPath = SvtPathOptions().GetWorkPath();
mxFileDlg->setDisplayDirectory( maPath );
}
More information about the Libreoffice-commits
mailing list