[Libreoffice-commits] core.git: sal/osl

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Wed Jan 16 14:50:53 UTC 2019


 sal/osl/unx/pipe.cxx |   46 +++++++++++++++-------------------------------
 1 file changed, 15 insertions(+), 31 deletions(-)

New commits:
commit 673a90cc3e606b05062ac27e1f01801cf415564a
Author:     Stephan Bergmann <sbergman at redhat.com>
AuthorDate: Wed Jan 16 13:30:32 2019 +0100
Commit:     Stephan Bergmann <sbergman at redhat.com>
CommitDate: Wed Jan 16 15:50:28 2019 +0100

    Use OString for memory management of getBootstrapSocketPath
    
    Change-Id: If1187cbb428d329fa10070662282d7fc3aeaf9de
    Reviewed-on: https://gerrit.libreoffice.org/66441
    Tested-by: Jenkins
    Reviewed-by: Stephan Bergmann <sbergman at redhat.com>

diff --git a/sal/osl/unx/pipe.cxx b/sal/osl/unx/pipe.cxx
index 10cb87770128..c07d1887bc86 100644
--- a/sal/osl/unx/pipe.cxx
+++ b/sal/osl/unx/pipe.cxx
@@ -25,7 +25,7 @@
 #include <osl/interlck.h>
 #include <rtl/string.h>
 #include <rtl/ustring.h>
-#include <rtl/bootstrap.h>
+#include <rtl/bootstrap.hxx>
 #include <sal/log.hxx>
 
 #include "sockimpl.hxx"
@@ -33,6 +33,7 @@
 #include "unixerrnostring.hxx"
 
 #include <cassert>
+#include <cstring>
 
 #define PIPEDEFAULTPATH     "/tmp"
 #define PIPEALTERNATEPATH   "/var/tmp"
@@ -127,38 +128,16 @@ oslPipe SAL_CALL osl_createPipe(rtl_uString *ustrPipeName, oslPipeOptions Option
 
 }
 
-static bool
-cpyBootstrapSocketPath(sal_Char *name, size_t len)
+static OString
+getBootstrapSocketPath()
 {
-    bool bRet = false;
-    rtl_uString *pName = nullptr, *pValue = nullptr;
+    OUString pValue;
 
-    rtl_uString_newFromAscii(&pName, "OSL_SOCKET_PATH");
-
-    if (rtl_bootstrap_get(pName, &pValue, nullptr))
+    if (rtl::Bootstrap::get("OSL_SOCKET_PATH", pValue))
     {
-        if (pValue && pValue->length > 0)
-        {
-            rtl_String *pStrValue = nullptr;
-
-            rtl_uString2String(&pStrValue, pValue->buffer,
-                               pValue->length, RTL_TEXTENCODING_UTF8,
-                               OUSTRING_TO_OSTRING_CVTFLAGS);
-            if (pStrValue)
-            {
-                if (pStrValue->length > 0)
-                {
-                    size_t nCopy = (len-1 < static_cast<size_t>(pStrValue->length)) ? len-1 : static_cast<size_t>(pStrValue->length);
-                    strncpy (name, pStrValue->buffer, nCopy);
-                    name[nCopy] = '\0';
-                    bRet = static_cast<size_t>(pStrValue->length) < len;
-                }
-                rtl_string_release(pStrValue);
-            }
-        }
-        rtl_uString_release(pName);
+        return OUStringToOString(pValue, RTL_TEXTENCODING_UTF8);
     }
-    return bRet;
+    return "";
 }
 
 static oslPipe osl_psz_createPipe(const sal_Char *pszPipeName, oslPipeOptions Options,
@@ -177,8 +156,13 @@ static oslPipe osl_psz_createPipe(const sal_Char *pszPipeName, oslPipeOptions Op
         strncpy(name, PIPEDEFAULTPATH, sizeof(name));
     else if (access(PIPEALTERNATEPATH, W_OK) == 0)
         strncpy(name, PIPEALTERNATEPATH, sizeof(name));
-    else if (!cpyBootstrapSocketPath (name, sizeof (name)))
-        return nullptr;
+    else {
+        auto const path = getBootstrapSocketPath ();
+        if (path.isEmpty() || sal_uInt32(path.getLength()) > sizeof(name) - 1) {
+            return nullptr;
+        }
+        std::memcpy(name, path.getStr(), sal_uInt32(path.getLength()) + 1);
+    }
 
     name[sizeof(name)-1] = '\0';  // ensure the string is NULL-terminated
     nNameLength = strlen(name);


More information about the Libreoffice-commits mailing list