From 623007d4c3151146f6a115d17cbd2dc4f123700f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marc-Andr=C3=A9=20Laverdi=C3=A8re?= <marc-andre@atc.tcs.com>
Date: Fri, 15 Jun 2012 11:42:00 -0400
Subject: [PATCH] Fixed invalid memory access

Change-Id: I5270921d72e7140851fa25f75688a0d98c444ab9
---
 vcl/unx/generic/app/sm.cxx |   22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/vcl/unx/generic/app/sm.cxx b/vcl/unx/generic/app/sm.cxx
index 82fd4b1..2031631 100644
--- a/vcl/unx/generic/app/sm.cxx
+++ b/vcl/unx/generic/app/sm.cxx
@@ -210,22 +210,28 @@ static void BuildSmPropertyList()
         pSmProps[ 2 ].vals[2].length    = aRestartOptionNoLogo.getLength()+1;
         pSmProps[ 2 ].vals[2].value = strdup(aRestartOptionNoLogo.getStr());
 
-        rtl::OUString aUserName;
-        rtl::OString aUser;
+        pSmProps[ 3 ].name      = const_cast<char*>(SmUserID);
+        pSmProps[ 3 ].type      = const_cast<char*>(SmARRAY8);
+        pSmProps[ 3 ].num_vals  = 1;
+        pSmProps[ 3 ].vals      = new SmPropValue;
+
         oslSecurity aSec = osl_getCurrentSecurity();
         if( aSec )
         {
+            rtl::OUString aUserName;
+            rtl::OString aUser;
             osl_getUserName( aSec, &aUserName.pData );
             aUser = rtl::OUStringToOString( aUserName, osl_getThreadTextEncoding() );
             osl_freeSecurityHandle( aSec );
+            pSmProps[ 3 ].vals->length  = aUser.getLength() + 1 ;
+            pSmProps[ 3 ].vals->value   = strndup( aUser.getStr(), pSmProps[ 3 ].vals->length );
+        }
+        else
+        {
+            //pSmProps[ 3 ].vals->value   = "";
+            pSmProps[ 3 ].vals->length  = 0;
         }
 
-        pSmProps[ 3 ].name      = const_cast<char*>(SmUserID);
-        pSmProps[ 3 ].type      = const_cast<char*>(SmARRAY8);
-        pSmProps[ 3 ].num_vals  = 1;
-        pSmProps[ 3 ].vals      = new SmPropValue;
-        pSmProps[ 3 ].vals->value   = strdup( aUser.getStr() );
-        pSmProps[ 3 ].vals->length  = strlen( (char *)pSmProps[ 3 ].vals->value )+1;
 
         pSmProps[ 4 ].name      = const_cast<char*>(SmRestartStyleHint);
         pSmProps[ 4 ].type      = const_cast<char*>(SmCARD8);
-- 
1.7.10.2

