[Libreoffice-commits] core.git: Branch 'libreoffice-6-0' - 2 commits - sc/source shell/Library_localebe.mk shell/source

Eike Rathke erack at redhat.com
Thu Dec 7 12:06:16 UTC 2017


 sc/source/core/data/document.cxx                 |    2 -
 shell/Library_localebe.mk                        |    1 
 shell/source/backends/localebe/localebackend.cxx |   34 ++++++++++++++++++-----
 3 files changed, 29 insertions(+), 8 deletions(-)

New commits:
commit bfe2fb8ceed6643574010bf7b40f04d149f0fd6d
Author: Eike Rathke <erack at redhat.com>
Date:   Wed Dec 6 13:21:50 2017 +0100

    Handle conversion from glibc locale to BCP 47 language tag
    
    The backend's ImplGetLocale() didn't handle variants, so
    ca_ES at valencia ended up as ca-ES instead of ca-ES-valencia, which
    made a difference with for example the UI language being set to
    Default resulting in only ca instead of ca-valencia, which then
    is also written to /org.openoffice.Setup/L10N/ooLocale during
    startup and obtained later.
    
    This only for the *iX branch, no idea if and what could be
    adjusted for Windows or MacOSX.
    
    Change-Id: I050f6f643571ccdc669fb91b06f3bb516f96e8d5
    Reviewed-on: https://gerrit.libreoffice.org/45946
    Reviewed-by: Eike Rathke <erack at redhat.com>
    Tested-by: Jenkins <ci at libreoffice.org>
    (cherry picked from commit c2bd06120b932bf3757f19bdf8c8d9ee8a31f557)
    Reviewed-on: https://gerrit.libreoffice.org/45980

diff --git a/shell/Library_localebe.mk b/shell/Library_localebe.mk
index 7c4931b2ce39..b8d8aba8f15c 100644
--- a/shell/Library_localebe.mk
+++ b/shell/Library_localebe.mk
@@ -22,6 +22,7 @@ $(eval $(call gb_Library_use_libraries,localebe1,\
 	cppu \
 	cppuhelper \
 	sal \
+	i18nlangtag \
 ))
 
 $(eval $(call gb_Library_set_componentfile,localebe1,shell/source/backends/localebe/localebe1))
diff --git a/shell/source/backends/localebe/localebackend.cxx b/shell/source/backends/localebe/localebackend.cxx
index 7ff388a1f26d..3392bb73cfc0 100644
--- a/shell/source/backends/localebe/localebackend.cxx
+++ b/shell/source/backends/localebe/localebackend.cxx
@@ -28,6 +28,8 @@
 #include <osl/time.h>
 #include <rtl/character.hxx>
 #include <o3tl/char16_t2wchar_t.hxx>
+#include <i18nlangtag/languagetag.hxx>
+#include <i18nlangtag/mslangid.hxx>
 
 #include <stdio.h>
 
@@ -184,16 +186,19 @@ static css::beans::Optional<css::uno::Any> ImplGetLocale(char const * category)
 
     const char *cp;
     const char *uscore = nullptr;
+    const char *end = nullptr;
 
     // locale string have the format lang[_ctry][.encoding][@modifier]
-    // we are only interested in the first two items, so we handle
-    // '.' and '@' as string end.
+    // Let LanguageTag handle all conversion, but do a sanity and length check
+    // first.
+    // For the fallback we are only interested in the first two items, so we
+    // handle '.' and '@' as string end for that.
     for (cp = locale; *cp; cp++)
     {
-        if (*cp == '_')
+        if (*cp == '_' && !uscore)
             uscore = cp;
-        if (*cp == '.' || *cp == '@')
-            break;
+        if ((*cp == '.' || *cp == '@') && !end)
+            end = cp;
         if (!rtl::isAscii(static_cast<unsigned char>(*cp))) {
             SAL_INFO("shell", "locale env var with non-ASCII content");
             return {false, {}};
@@ -205,16 +210,31 @@ static css::beans::Optional<css::uno::Any> ImplGetLocale(char const * category)
         return {false, {}};
     }
 
+    // This is a tad awkward.. but the easiest way to obtain what we're
+    // actually interested in. For example this also converts
+    // "ca_ES.UTF-8 at valencia" to "ca-ES-valencia".
+    const OString aLocaleStr(locale);
+    const LanguageType nLang = MsLangId::convertUnxByteStringToLanguage( aLocaleStr);
+    if (nLang != LANGUAGE_DONTKNOW)
+    {
+        const OUString aLangTagStr( LanguageTag::convertToBcp47( nLang));
+        return {true, css::uno::Any(aLangTagStr)};
+    }
+
+    // As a fallback, strip encoding and modifier and return just a
+    // language-country combination and let the caller handle unknowns.
     OUStringBuffer aLocaleBuffer;
+    if (!end)
+        end = cp;
     if( uscore != nullptr )
     {
         aLocaleBuffer.appendAscii(locale, uscore++ - locale);
         aLocaleBuffer.append("-");
-        aLocaleBuffer.appendAscii(uscore, cp - uscore);
+        aLocaleBuffer.appendAscii(uscore, end - uscore);
     }
     else
     {
-        aLocaleBuffer.appendAscii(locale, cp - locale);
+        aLocaleBuffer.appendAscii(locale, end - locale);
     }
 
     return {true, css::uno::Any(aLocaleBuffer.makeStringAndClear())};
commit d17dfb3dc1cc7fd91ede9a58337d89e38fd3b022
Author: Eike Rathke <erack at redhat.com>
Date:   Wed Dec 6 20:08:08 2017 +0100

    Prevent out-of-bounds access, tdf#114228 related
    
    Such document access should be validated, specifically if it's
    called from accessibility.
    
    Change-Id: I67fa14c7fb1bf3885fc009428b981149f3f448fb
    Reviewed-on: https://gerrit.libreoffice.org/45978
    Reviewed-by: Eike Rathke <erack at redhat.com>
    Tested-by: Eike Rathke <erack at redhat.com>
    (cherry picked from commit 7265e75f8b34cc1043b972478e8b499566660f86)
    Reviewed-on: https://gerrit.libreoffice.org/45979
    Tested-by: Jenkins <ci at libreoffice.org>

diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index 2151269a1612..2d1834d57cd9 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -3681,7 +3681,7 @@ sal_uInt32 ScDocument::GetNumberFormat( const ScRange& rRange ) const
     SCCOL nCol1 = rRange.aStart.Col(), nCol2 = rRange.aEnd.Col();
     SCROW nRow1 = rRange.aStart.Row(), nRow2 = rRange.aEnd.Row();
 
-    if (!ValidTab(nTab1) || !ValidTab(nTab2) || !maTabs[nTab1] || !maTabs[nTab2])
+    if (!TableExists(nTab1) || !TableExists(nTab2))
         return 0;
 
     sal_uInt32 nFormat = 0;


More information about the Libreoffice-commits mailing list