[Libreoffice-commits] .: extensions/source

Caolán McNamara caolan at kemper.freedesktop.org
Thu May 3 14:34:44 PDT 2012


 extensions/source/plugin/base/context.cxx |    7 ++++++-
 extensions/source/plugin/unx/mediator.cxx |    9 +++++++--
 extensions/source/scanner/sane.cxx        |    6 ++++--
 3 files changed, 17 insertions(+), 5 deletions(-)

New commits:
commit 76cc8aca4270bc2542cc8444d07f80d578eb6581
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Thu May 3 22:33:54 2012 +0100

    WaE: unchecked results from write/fwrite
    
    Change-Id: Ia7943a132d05e596550bd71878b54b2825c31987

diff --git a/extensions/source/plugin/base/context.cxx b/extensions/source/plugin/base/context.cxx
index 05978fe..217a4bb 100644
--- a/extensions/source/plugin/base/context.cxx
+++ b/extensions/source/plugin/base/context.cxx
@@ -44,6 +44,7 @@
 
 #include <plugin/impl.hxx>
 
+#include <sal/log.hxx>
 #include <com/sun/star/frame/FrameSearchFlag.hpp>
 #include <com/sun/star/frame/XComponentLoader.hpp>
 #include <tools/fsys.hxx>
@@ -340,7 +341,11 @@ void FileSink::closeOutput() throw()
 void FileSink::writeBytes( const Sequence<sal_Int8>& Buffer ) throw()
 {
     if( fp )
-        fwrite( Buffer.getConstArray(), 1, Buffer.getLength(), fp );
+    {
+        size_t nItems = Buffer.getLength();
+        bool bSuccess = (fwrite(Buffer.getConstArray(), 1, nItems, fp) == nItems);
+        SAL_WARN_IF( !bSuccess, "extensions", "short write");
+    }
 }
 
 void FileSink::flush() throw()
diff --git a/extensions/source/plugin/unx/mediator.cxx b/extensions/source/plugin/unx/mediator.cxx
index a98e19e..4edefaa 100644
--- a/extensions/source/plugin/unx/mediator.cxx
+++ b/extensions/source/plugin/unx/mediator.cxx
@@ -30,6 +30,7 @@
 #include <unistd.h>
 
 #include <plugin/unx/mediator.hxx>
+#include <sal/log.hxx>
 #include <vcl/svapp.hxx>
 
 #define MEDIATOR_MAGIC 0xf7a8d2f4
@@ -59,7 +60,9 @@ Mediator::~Mediator()
             aHeader[0] = 0;
             aHeader[1] = 0;
             aHeader[2] = MEDIATOR_MAGIC;
-            write( m_nSocket, aHeader, sizeof( aHeader ) );
+            ssize_t nToWrite = sizeof(aHeader);
+            bool bSuccess = (nToWrite == write(m_nSocket, aHeader, nToWrite));
+            SAL_WARN_IF( !bSuccess, "extensions", "short write");
         }
         // kick the thread out of its run method; it deletes itself
         close( m_nSocket );
@@ -95,7 +98,9 @@ sal_uLong Mediator::SendMessage( sal_uLong nBytes, const char* pBytes, sal_uLong
     pBuffer[ 1 ] = nBytes;
     pBuffer[ 2 ] = MEDIATOR_MAGIC;
     memcpy( &pBuffer[3], pBytes, (size_t)nBytes );
-    write( m_nSocket, pBuffer, nBytes + 3*sizeof( sal_uLong ) );
+    ssize_t nToWrite = nBytes + 3*sizeof( sal_uLong );
+    bool bSuccess = (nToWrite == write( m_nSocket, pBuffer, nToWrite ));
+    SAL_WARN_IF( !bSuccess, "extensions", "short write");
     delete [] pBuffer;
 
     return nMessageID;
diff --git a/extensions/source/scanner/sane.cxx b/extensions/source/scanner/sane.cxx
index b89f9bd..0e0ff64 100644
--- a/extensions/source/scanner/sane.cxx
+++ b/extensions/source/scanner/sane.cxx
@@ -748,12 +748,14 @@ sal_Bool Sane::Start( BitmapTransporter& rBitmap )
                 if( nLen && ( nStatus == SANE_STATUS_GOOD ||
                               nStatus == SANE_STATUS_EOF ) )
                 {
-                    fwrite( pBuffer, 1, nLen, pFrame );
+                    bSuccess = (static_cast<size_t>(nLen) == fwrite( pBuffer, 1, nLen, pFrame ));
+                    if (!bSuccess)
+                        break;
                 }
                 else
                     DUMP_STATE( nStatus, "sane_read" );
             } while( nStatus == SANE_STATUS_GOOD );
-            if( nStatus != SANE_STATUS_EOF )
+            if (nStatus != SANE_STATUS_EOF || !bSuccess)
             {
                 fclose( pFrame );
                 bSuccess = sal_False;


More information about the Libreoffice-commits mailing list