From e55ee82f519064319dddcd3dc4553c6580dcd93a Mon Sep 17 00:00:00 2001 From: Michael Stahl Date: Thu, 7 Sep 2017 14:12:25 +0200 Subject: 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 --- extensions/source/logging/csvformatter.cxx | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'extensions') 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 #include #include +#include #include #include @@ -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(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, -- cgit