The patch solves this bug:
https://bugs.freedesktop.org/show_bug.cgi?id=42492
There was a buffer overflow: char aBuffer[16] had no room for the
terminating null character.
But the hex command was still wrong, because the printf used "%X" and
"%lX", which are very platform-dependent.
Actually the "integer" is only 16-bit, and "long" is only 32-bit. I've
corrected this by using "%"SAL_PRIXUINT32 as described in
http://wiki.documentfoundation.org/Development/Sal_Types (and there is no
SAL_PRIXUINT16, so both were converted to sal_uInt32).

Regards,
Uray M. János
From d7a39a31a9b39edab1c3354748c5383b1b57b924 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?"Uray=20M.=20J=C3=A1nos"?= <uray.ja...@gmail.com>
Date: Tue, 31 Jul 2012 08:04:06 +0200
Subject: [PATCH] fdo#42492: fixing Basic HEX command

Change-Id: I133590c9f2a34d8daab031da0c77bd049d275c29
---
 basic/source/runtime/methods.cxx |   11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/basic/source/runtime/methods.cxx b/basic/source/runtime/methods.cxx
index 7050093..c06e0d7 100644
--- a/basic/source/runtime/methods.cxx
+++ b/basic/source/runtime/methods.cxx
@@ -871,12 +871,13 @@ RTLFUNC(Hex)
         StarBASIC::Error( SbERR_BAD_ARGUMENT );
     else
     {
-        char aBuffer[16];
+        char aBuffer[17];
         SbxVariableRef pArg = rPar.Get( 1 );
-        if ( pArg->IsInteger() )
-            snprintf( aBuffer, sizeof(aBuffer), "%X", pArg->GetInteger() );
-        else
-            snprintf( aBuffer, sizeof(aBuffer), "%lX", static_cast<long unsigned int>(pArg->GetLong()) );
+        // converting value to unsigned
+        sal_uInt32 nVal = pArg->IsInteger() ?
+            static_cast<sal_uInt16>(pArg->GetInteger()) :
+            static_cast<sal_uInt32>(pArg->GetLong());
+        snprintf( aBuffer, sizeof(aBuffer), "%"SAL_PRIXUINT32, nVal );
         rPar.Get(0)->PutString( rtl::OUString::createFromAscii( aBuffer ) );
     }
 }
-- 
1.7.7

_______________________________________________
LibreOffice mailing list
LibreOffice@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice

Reply via email to