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

Stephan Bergmann sbergman at redhat.com
Wed Apr 2 01:43:49 PDT 2014


 sal/Library_sal.mk       |    2 
 sal/osl/unx/security.c   |  501 ----------------------------------------------
 sal/osl/unx/security.cxx |  511 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 512 insertions(+), 502 deletions(-)

New commits:
commit 6cd87e5ee27af05cf54ba56d06f519a8f7138e8a
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Wed Apr 2 10:42:34 2014 +0200

    coverity#1194930 Avoid TOCTOU between access and mkdir
    
    Change-Id: I6567313abdacd06b59f7004c970b954a4b42419e

diff --git a/sal/osl/unx/security.cxx b/sal/osl/unx/security.cxx
index 77764b5..d2b1c1d 100644
--- a/sal/osl/unx/security.cxx
+++ b/sal/osl/unx/security.cxx
@@ -25,6 +25,7 @@
 #include <osl/security.h>
 #include <osl/diagnose.h>
 #include <rtl/bootstrap.h>
+#include <sal/log.hxx>
 
 #include "osl/thread.h"
 #include "osl/file.h"
@@ -395,7 +396,6 @@ static sal_Bool SAL_CALL osl_psz_getConfigDir(oslSecurity Security, sal_Char* ps
     if (pStr == NULL || strlen(pStr) == 0 || access(pStr, 0) != 0)
     {
         size_t n = 0;
-        sal_Bool dirOK = sal_True;
 
         // a default equal to $HOME/.config should be used.
         if (!osl_psz_getHomeDir(Security, pszDirectory, nMax))
@@ -406,34 +406,44 @@ static sal_Bool SAL_CALL osl_psz_getConfigDir(oslSecurity Security, sal_Char* ps
             strncpy(pszDirectory+n, DOT_CONFIG, sizeof(DOT_CONFIG));
 
             // try to create dir if not present
-            if (access(pszDirectory, F_OK) != 0 && mkdir(pszDirectory, S_IRWXU) != 0)
-                dirOK = sal_False;
-            else
+            bool dirOK = true;
+            if (mkdir(pszDirectory, S_IRWXU) != 0)
+            {
+                int e = errno;
+                if (e != EEXIST)
+                {
+                    SAL_WARN(
+                        "sal.osl",
+                        "mkdir(" << pszDirectory << "): errno=" << e);
+                    dirOK = false;
+                }
+            }
+            if (dirOK)
             {
                 // check file type and permissions
                 struct stat st;
                 if (stat(pszDirectory, &st) != 0)
                 {
                     OSL_TRACE("Could not stat $HOME/.config");
-                    dirOK = sal_False;
+                    dirOK = false;
                 }
                 else
                 {
                     if (!S_ISDIR(st.st_mode))
                     {
                         OSL_TRACE("$HOME/.config is not a directory");
-                        dirOK = sal_False;
+                        dirOK = false;
                     }
                     if (!(st.st_mode & S_IRUSR && st.st_mode & S_IWUSR && st.st_mode & S_IXUSR))
                     {
                         OSL_TRACE("$HOME/.config has bad permissions");
-                        dirOK = sal_False;
+                        dirOK = false;
                     }
                 }
             }
 
             // resort to HOME
-            if (dirOK == sal_False)
+            if (!dirOK)
                 pszDirectory[n] = '\0';
         }
     }
commit d37e9645edbdabaaf16ce0f1f904405f3477dc41
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Wed Apr 2 10:36:04 2014 +0200

    sal/osl/unx/security.c -> .cxx
    
    Change-Id: If8dbfa3e26a02ac3d5ee0077f730eeca4b59c4d7

diff --git a/sal/Library_sal.mk b/sal/Library_sal.mk
index ec8d89b..2103fe8 100644
--- a/sal/Library_sal.mk
+++ b/sal/Library_sal.mk
@@ -164,6 +164,7 @@ $(eval $(call gb_Library_add_exception_objects,sal,\
 	sal/osl/unx/process \
 	sal/osl/unx/process_impl \
 	sal/osl/unx/profile \
+	sal/osl/unx/security \
         $(if $(filter DESKTOP,$(BUILD_TYPE)), sal/osl/unx/salinit) \
 ))
 $(eval $(call gb_Library_add_cobjects,sal,\
@@ -172,7 +173,6 @@ $(eval $(call gb_Library_add_cobjects,sal,\
 	sal/osl/unx/nlsupport \
 	sal/osl/unx/pipe \
 	sal/osl/unx/readwrite_helper \
-	sal/osl/unx/security \
 	sal/osl/unx/socket \
 	sal/osl/unx/system \
 	sal/osl/unx/tempfile \
diff --git a/sal/osl/unx/security.c b/sal/osl/unx/security.cxx
similarity index 97%
rename from sal/osl/unx/security.c
rename to sal/osl/unx/security.cxx
index 3806a0f..77764b5 100644
--- a/sal/osl/unx/security.c
+++ b/sal/osl/unx/security.cxx
@@ -43,7 +43,7 @@
 static oslSecurityError SAL_CALL
 osl_psz_loginUser(const sal_Char* pszUserName, const sal_Char* pszPasswd,
                   oslSecurity* pSecurity);
-sal_Bool SAL_CALL osl_psz_getUserIdent(oslSecurity Security, sal_Char *pszIdent, sal_uInt32 nMax);
+extern "C" sal_Bool SAL_CALL osl_psz_getUserIdent(oslSecurity Security, sal_Char *pszIdent, sal_uInt32 nMax);
 static sal_Bool SAL_CALL osl_psz_getUserName(oslSecurity Security, sal_Char* pszName, sal_uInt32  nMax);
 static sal_Bool SAL_CALL osl_psz_getHomeDir(oslSecurity Security, sal_Char* pszDirectory, sal_uInt32 nMax);
 static sal_Bool SAL_CALL osl_psz_getConfigDir(oslSecurity Security, sal_Char* pszDirectory, sal_uInt32 nMax);
@@ -91,7 +91,7 @@ static oslSecurityImpl * growSecurityImpl(
             *bufSize = SIZE_MAX - offsetof(oslSecurityImpl, m_buffer);
             n = SIZE_MAX;
         }
-        p = realloc(impl, n);
+        p = static_cast<oslSecurityImpl *>(realloc(impl, n));
         memset (p, 0, n);
     }
     if (p == NULL) {
@@ -233,8 +233,8 @@ sal_Bool SAL_CALL osl_psz_getUserIdent(oslSecurity Security, sal_Char *pszIdent,
         return sal_False;
 
     nChr = snprintf(buffer, sizeof(buffer), "%u", pSecImpl->m_pPasswd.pw_uid);
-    if ( nChr < 0 || SAL_INT_CAST(sal_uInt32, nChr) >= sizeof(buffer)
-         || SAL_INT_CAST(sal_uInt32, nChr) >= nMax )
+    if ( nChr < 0 || sal::static_int_cast<sal_uInt32>(nChr) >= sizeof(buffer)
+         || sal::static_int_cast<sal_uInt32>(nChr) >= nMax )
         return sal_False; /* leave *pszIdent unmodified in case of failure */
 
     memcpy(pszIdent, buffer, nChr+1);
@@ -483,7 +483,7 @@ sal_Bool SAL_CALL osl_isAdministrator(oslSecurity Security)
 
 void SAL_CALL osl_freeSecurityHandle(oslSecurity Security)
 {
-    deleteSecurityImpl(Security);
+    deleteSecurityImpl(static_cast<oslSecurityImpl *>(Security));
 }
 
 


More information about the Libreoffice-commits mailing list