[Libreoffice-commits] core.git: extensions/source

Michael Stahl mstahl at redhat.com
Thu Sep 7 12:17:59 UTC 2017


 extensions/source/logging/csvformatter.cxx |   14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

New commits:
commit e55ee82f519064319dddcd3dc4553c6580dcd93a
Author: Michael Stahl <mstahl at redhat.com>
Date:   Thu Sep 7 14:12:25 2017 +0200

    extensions: GCC 7 -Werror=format-truncation
    
    Given a valid DateTime, the "buffer" is too small by 1 because
    Year can be negative with 4 digits.
    
    Most of the problem is that invalid DateTimes would overflow
    by up to 14 bytes; throw IllegalArgumentException for obviously
    invalid DateTime.
    
    Change-Id: I8af109425d5681b1b28454917664401a5404f251

diff --git a/extensions/source/logging/csvformatter.cxx b/extensions/source/logging/csvformatter.cxx
index 98e64e1c454d..249dac535365 100644
--- a/extensions/source/logging/csvformatter.cxx
+++ b/extensions/source/logging/csvformatter.cxx
@@ -23,6 +23,7 @@
 #include <com/sun/star/logging/XLogFormatter.hpp>
 #include <com/sun/star/uno/XComponentContext.hpp>
 #include <com/sun/star/lang/XServiceInfo.hpp>
+#include <com/sun/star/lang/IllegalArgumentException.hpp>
 
 #include <cppuhelper/implbase.hxx>
 #include <cppuhelper/supportsservice.hxx>
@@ -227,8 +228,19 @@ namespace logging
 
         if(m_LogTimestamp)
         {
+            if (   record.LogTime.Year < -9999 || 9999 < record.LogTime.Year
+                || record.LogTime.Month < 1 || 12 < record.LogTime.Month
+                || record.LogTime.Day < 1 || 31 < record.LogTime.Day
+                || 24 < record.LogTime.Hours
+                || 60 < record.LogTime.Minutes
+                || 60 < record.LogTime.Seconds
+                || 999999999 < record.LogTime.NanoSeconds)
+            {
+                throw css::lang::IllegalArgumentException("invalid date", static_cast<cppu::OWeakObject*>(this), 1);
+            }
+
             // ISO 8601
-            char buffer[ 30 ];
+            char buffer[ 31 ];
             const size_t buffer_size = sizeof( buffer );
             snprintf( buffer, buffer_size, "%04i-%02i-%02iT%02i:%02i:%02i.%09i",
                 (int)record.LogTime.Year,


More information about the Libreoffice-commits mailing list