bridges/source/cpp_uno/shared/vtablefactory.cxx |   29 ++++++++++++------------
 include/rtl/strbuf.hxx                          |    7 +++++
 include/rtl/ustrbuf.hxx                         |    7 +++++
 3 files changed, 29 insertions(+), 14 deletions(-)

New commits:
commit 8fb5be18f8febe88f7d0b72e4b30efd41891feb7
Author:     Stephan Bergmann <[email protected]>
AuthorDate: Fri Jan 16 08:34:26 2026 +0100
Commit:     Stephan Bergmann <[email protected]>
CommitDate: Tue Jan 20 07:33:22 2026 +0100

    Use OStringBuffer as a pad for the mutable string passed to mkstemp
    
    ...by introducing OStringBuffer::getMutableStr and (for consistency)
    OUStringBuffer::getMutableStr
    
    Change-Id: I4dfc3b8d8ffb49b8b3742600081d075536b312e5
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/197605
    Reviewed-by: Stephan Bergmann <[email protected]>
    Tested-by: Jenkins

diff --git a/bridges/source/cpp_uno/shared/vtablefactory.cxx 
b/bridges/source/cpp_uno/shared/vtablefactory.cxx
index 96077742ebdb..d8dd4897772f 100644
--- a/bridges/source/cpp_uno/shared/vtablefactory.cxx
+++ b/bridges/source/cpp_uno/shared/vtablefactory.cxx
@@ -30,7 +30,6 @@
 #include <sal/log.hxx>
 #include <sal/types.h>
 
-#include <memory>
 #include <new>
 #include <unordered_map>
 #include <vector>
@@ -49,6 +48,7 @@
 
 #if defined USE_DOUBLE_MMAP
 #include <fcntl.h>
+#include <rtl/strbuf.hxx>
 #endif
 
 #if defined MACOSX && defined __aarch64__
@@ -258,28 +258,29 @@ bool VtableFactory::createBlock(Block &block, sal_Int32 
slotCount) const
     }
 
     osl::Security aSecurity;
-    OUString strDirectory;
+    OString strDirectory;
     OUString strURLDirectory;
     if (aSecurity.getHomeDir(strURLDirectory))
-        osl::File::getSystemPathFromFileURL(strURLDirectory, strDirectory);
+    {
+        OUString s;
+        osl::File::getSystemPathFromFileURL(strURLDirectory, s);
+        strDirectory = OUStringToOString(s, osl_getThreadTextEncoding());
+    }
 
     for (int i = strDirectory.isEmpty() ? 1 : 0; i < 2; ++i)
     {
-        if (strDirectory.isEmpty())
-            strDirectory = "/tmp";
-
-        strDirectory += "/.execoooXXXXXX";
-        OString aTmpName = OUStringToOString(strDirectory, 
osl_getThreadTextEncoding());
-        std::unique_ptr<char[]> tmpfname(new char[aTmpName.getLength()+1]);
-        strncpy(tmpfname.get(), aTmpName.getStr(), aTmpName.getLength()+1);
-        if ((block.fd = mkstemp(tmpfname.get())) == -1)
-            fprintf(stderr, "mkstemp(\"%s\") failed: %s
", tmpfname.get(), strerror(errno));
+        OStringBuffer aTmpName(strDirectory);
+        if (aTmpName.isEmpty())
+            aTmpName = "/tmp";
+
+        aTmpName.append("/.execoooXXXXXX");
+        if ((block.fd = mkstemp(aTmpName.getMutableStr())) == -1)
+            fprintf(stderr, "mkstemp(\"%s\") failed: %s
", aTmpName.getStr(), strerror(errno));
         if (block.fd == -1)
         {
             break;
         }
-        unlink(tmpfname.get());
-        tmpfname.reset();
+        unlink(aTmpName.getStr());
 
         int err;
 #if defined(HAVE_POSIX_FALLOCATE)
diff --git a/include/rtl/strbuf.hxx b/include/rtl/strbuf.hxx
index dd37ecfce673..82cc86038a41 100644
--- a/include/rtl/strbuf.hxx
+++ b/include/rtl/strbuf.hxx
@@ -498,6 +498,13 @@ public:
      */
     const char* getStr() const SAL_RETURNS_NONNULL { return pData->buffer; }
 
+#if defined LIBO_INTERNAL_ONLY
+    // Provide unsafe non-const access to the null-terminated string.  Callers 
can mutate the
+    // contents of the string buffer (including introducing embedded null 
characters), but cannot
+    // modify its length.
+    char * getMutableStr() SAL_RETURNS_NONNULL { return pData->buffer; }
+#endif
+
     /**
       Access to individual characters.
 
diff --git a/include/rtl/ustrbuf.hxx b/include/rtl/ustrbuf.hxx
index 05cc5f170d52..8a162ee664a4 100644
--- a/include/rtl/ustrbuf.hxx
+++ b/include/rtl/ustrbuf.hxx
@@ -519,6 +519,13 @@ public:
      */
     const sal_Unicode*  getStr() const SAL_RETURNS_NONNULL { return 
pData->buffer; }
 
+#if defined LIBO_INTERNAL_ONLY
+    // Provide unsafe non-const access to the null-terminated string.  Callers 
can mutate the
+    // contents of the string buffer (including introducing embedded null 
characters), but cannot
+    // modify its length.
+    sal_Unicode * getMutableStr() SAL_RETURNS_NONNULL { return pData->buffer; }
+#endif
+
     /**
       Access to individual characters.
 

Reply via email to