diff options
author | Michael Stahl <mstahl@redhat.com> | 2017-09-07 14:12:25 +0200 |
---|---|---|
committer | Michael Stahl <mstahl@redhat.com> | 2017-09-07 14:16:12 +0200 |
commit | e55ee82f519064319dddcd3dc4553c6580dcd93a (patch) | |
tree | 3fdf432466aad81290730626a511aaa4a85ee106 /extensions | |
parent | 3829949e91c578bc9e99858ec170f0c6736d9828 (diff) |
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
Diffstat (limited to 'extensions')
-rw-r--r-- | extensions/source/logging/csvformatter.cxx | 14 |
1 files changed, 13 insertions, 1 deletions
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, |