Kaydet (Commit) 673a90cc authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Use OString for memory management of getBootstrapSocketPath

Change-Id: If1187cbb428d329fa10070662282d7fc3aeaf9de
Reviewed-on: https://gerrit.libreoffice.org/66441
Tested-by: Jenkins
Reviewed-by: 's avatarStephan Bergmann <sbergman@redhat.com>
üst 28dee112
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
#include <osl/interlck.h> #include <osl/interlck.h>
#include <rtl/string.h> #include <rtl/string.h>
#include <rtl/ustring.h> #include <rtl/ustring.h>
#include <rtl/bootstrap.h> #include <rtl/bootstrap.hxx>
#include <sal/log.hxx> #include <sal/log.hxx>
#include "sockimpl.hxx" #include "sockimpl.hxx"
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include "unixerrnostring.hxx" #include "unixerrnostring.hxx"
#include <cassert> #include <cassert>
#include <cstring>
#define PIPEDEFAULTPATH "/tmp" #define PIPEDEFAULTPATH "/tmp"
#define PIPEALTERNATEPATH "/var/tmp" #define PIPEALTERNATEPATH "/var/tmp"
...@@ -127,38 +128,16 @@ oslPipe SAL_CALL osl_createPipe(rtl_uString *ustrPipeName, oslPipeOptions Option ...@@ -127,38 +128,16 @@ oslPipe SAL_CALL osl_createPipe(rtl_uString *ustrPipeName, oslPipeOptions Option
} }
static bool static OString
cpyBootstrapSocketPath(sal_Char *name, size_t len) getBootstrapSocketPath()
{ {
bool bRet = false; OUString pValue;
rtl_uString *pName = nullptr, *pValue = nullptr;
rtl_uString_newFromAscii(&pName, "OSL_SOCKET_PATH"); if (rtl::Bootstrap::get("OSL_SOCKET_PATH", pValue))
if (rtl_bootstrap_get(pName, &pValue, nullptr))
{ {
if (pValue && pValue->length > 0) return OUStringToOString(pValue, RTL_TEXTENCODING_UTF8);
{
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 bRet; return "";
} }
static oslPipe osl_psz_createPipe(const sal_Char *pszPipeName, oslPipeOptions Options, 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 ...@@ -177,8 +156,13 @@ static oslPipe osl_psz_createPipe(const sal_Char *pszPipeName, oslPipeOptions Op
strncpy(name, PIPEDEFAULTPATH, sizeof(name)); strncpy(name, PIPEDEFAULTPATH, sizeof(name));
else if (access(PIPEALTERNATEPATH, W_OK) == 0) else if (access(PIPEALTERNATEPATH, W_OK) == 0)
strncpy(name, PIPEALTERNATEPATH, sizeof(name)); strncpy(name, PIPEALTERNATEPATH, sizeof(name));
else if (!cpyBootstrapSocketPath (name, sizeof (name))) else {
return nullptr; 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 name[sizeof(name)-1] = '\0'; // ensure the string is NULL-terminated
nNameLength = strlen(name); nNameLength = strlen(name);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment