[Libreoffice-commits] core.git: shell/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Wed Feb 13 09:02:25 UTC 2019


 shell/source/backends/desktopbe/desktopbackend.cxx |   10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

New commits:
commit 91731a8674d764293e2988333027f82f15b2577e
Author:     Takeshi Abe <tabe at fixedpoint.jp>
AuthorDate: Tue Feb 12 23:38:29 2019 +0900
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Wed Feb 13 10:02:02 2019 +0100

    tdf#119890 Lookup XDG_(DOCUMENTS|TEMPLATES)_DIR correctly
    
    ... for My Documents and My Templates.
    
    It seems customary to name XDG_*_DIR in all uppercase.  This also
    fixes buffer overrun IIUC, as osl_readLine() does not return the
    newline delimiter.
    
    Change-Id: If85ca7e6abe663e29d36b65a08d358d3d7d27c4b
    Reviewed-on: https://gerrit.libreoffice.org/67741
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/shell/source/backends/desktopbe/desktopbackend.cxx b/shell/source/backends/desktopbe/desktopbackend.cxx
index 0860bcd421a1..4f3c2940869b 100644
--- a/shell/source/backends/desktopbe/desktopbackend.cxx
+++ b/shell/source/backends/desktopbe/desktopbackend.cxx
@@ -129,6 +129,7 @@ void Default::setPropertyValue(OUString const &, css::uno::Any const &)
 
 OUString xdg_user_dir_lookup (const char *type)
 {
+    size_t nLenType = strlen(type);
     char *config_home;
     char *p;
     bool bError = false;
@@ -161,11 +162,10 @@ OUString xdg_user_dir_lookup (const char *type)
         rtl::ByteSequence seq;
         while (osl_File_E_None == osl_readLine(handle , reinterpret_cast<sal_Sequence **>(&seq)))
         {
-            /* Remove newline at end */
             int relative = 0;
             int len = seq.getLength();
-            if(len>0 && seq[len-1] == '\n')
-                seq[len-1] = 0;
+            seq.realloc(len + 1);
+            seq[len] = 0;
 
             p = reinterpret_cast<char *>(seq.getArray());
             while (*p == ' ' || *p == '\t')
@@ -173,9 +173,9 @@ OUString xdg_user_dir_lookup (const char *type)
             if (strncmp (p, "XDG_", 4) != 0)
                 continue;
             p += 4;
-            if (strncmp (p, type, strlen (type)) != 0)
+            if (strncmp (p, OString(type, nLenType).toAsciiUpperCase().getStr(), nLenType) != 0)
                 continue;
-            p += strlen (type);
+            p += nLenType;
             if (strncmp (p, "_DIR", 4) != 0)
                 continue;
             p += 4;


More information about the Libreoffice-commits mailing list