From 673a90cc3e606b05062ac27e1f01801cf415564a Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Wed, 16 Jan 2019 13:30:32 +0100 Subject: Use OString for memory management of getBootstrapSocketPath Change-Id: If1187cbb428d329fa10070662282d7fc3aeaf9de Reviewed-on: https://gerrit.libreoffice.org/66441 Tested-by: Jenkins Reviewed-by: Stephan Bergmann --- sal/osl/unx/pipe.cxx | 46 +++++++++++++++------------------------------- 1 file changed, 15 insertions(+), 31 deletions(-) (limited to 'sal/osl/unx/pipe.cxx') 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 #include #include -#include +#include #include #include "sockimpl.hxx" @@ -33,6 +33,7 @@ #include "unixerrnostring.hxx" #include +#include #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(pStrValue->length)) ? len-1 : static_cast(pStrValue->length); - strncpy (name, pStrValue->buffer, nCopy); - name[nCopy] = '\0'; - bRet = static_cast(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); -- cgit