From 2b5ce52cddc16be5b3bb511b278bcfef3f706237 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Fri, 30 Oct 2015 17:28:28 +0100 Subject: Fix osl_getSystemPathFromFileURL URL scheme check Change-Id: If7737b9eaf11333facd9ae3faf58e36ba76c3b05 --- sal/osl/unx/file_url.cxx | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'sal') diff --git a/sal/osl/unx/file_url.cxx b/sal/osl/unx/file_url.cxx index 742b3f5a6a29..ee5f0382b6bc 100644 --- a/sal/osl/unx/file_url.cxx +++ b/sal/osl/unx/file_url.cxx @@ -32,6 +32,7 @@ #include #include +#include #include #include #include @@ -86,7 +87,6 @@ oslFileError SAL_CALL osl_getSystemPathFromFileURL( rtl_uString *ustrFileURL, rt rtl_uString * pTmp = NULL; sal_Unicode encodedSlash[3] = { '%', '2', 'F' }; - sal_Unicode protocolDelimiter[3] = { ':', '/', '/' }; /* a valid file url may not start with '/' */ if( ( 0 == ustrFileURL->length ) || ( '/' == ustrFileURL->buffer[0] ) ) @@ -94,12 +94,25 @@ oslFileError SAL_CALL osl_getSystemPathFromFileURL( rtl_uString *ustrFileURL, rt return osl_File_E_INVAL; } - /* Check for non file:// protocols */ - - nIndex = rtl_ustr_indexOfStr_WithLength( ustrFileURL->buffer, ustrFileURL->length, protocolDelimiter, 3 ); - if ( -1 != nIndex && (4 != nIndex || 0 != rtl_ustr_ascii_shortenedCompare_WithLength( ustrFileURL->buffer, ustrFileURL->length,"file", 4 ) ) ) - { - return osl_File_E_INVAL; + // Check for non file scheme: + if (rtl::isAsciiAlpha(ustrFileURL->buffer[0])) { + for (sal_Int32 i = 1; i != ustrFileURL->length; ++i) { + auto c = ustrFileURL->buffer[i]; + if (c == ':') { + if (rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths( + ustrFileURL->buffer, i, + RTL_CONSTASCII_STRINGPARAM("file")) + != 0) + { + return osl_File_E_INVAL; + } + break; + } else if (!rtl::isAsciiAlphanumeric(c) && c != '+' && c != '-' + && c != '.') + { + break; + } + } } /* search for encoded slashes (%2F) and decode every single token if we find one */ -- cgit