This is an automated email from the ASF dual-hosted git repository. rmiddleton pushed a commit to branch tz-offset-check in repository https://gitbox.apache.org/repos/asf/logging-log4cxx.git
commit eb0ae079ba58fddd024f2100a21dce0b8a7ede26 Author: Robert Middleton <[email protected]> AuthorDate: Mon Jan 27 22:15:43 2025 -0500 Add TZ offset check Add a TZ offset check to make sure that our timezone is in a reasonable range. Also clean up the SimpleDateFormatter slightly to make the code more clear. --- src/main/cpp/simpledateformat.cpp | 29 ++++++++++------------------- src/main/cpp/timezone.cpp | 7 +++++++ 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/main/cpp/simpledateformat.cpp b/src/main/cpp/simpledateformat.cpp index 4ad7b7ca..15017752 100644 --- a/src/main/cpp/simpledateformat.cpp +++ b/src/main/cpp/simpledateformat.cpp @@ -599,38 +599,29 @@ class RFC822TimeZoneToken : public PatternToken else { apr_int32_t off = tm.tm_gmtoff; - size_t basePos = s.length(); - s.append( LOG4CXX_STR( "+0000" ) ); + s.reserve(s.length() + 5); if ( off < 0 ) { - s[basePos] = 0x2D; // '-' + s.push_back( '-' ); off = -off; + }else{ + s.push_back( '+' ); } LogString hours; StringHelper::toString( off / 3600, p, hours ); - size_t hourPos = basePos + 2; - - // - // assumes that point values for 0-9 are same between char and wchar_t - // - for ( size_t i = hours.length(); i-- > 0; ) - { - s[hourPos--] = hours[i]; + if( hours.size() == 1 ){ + s.push_back( '0' ); } + s.append(hours); LogString min; StringHelper::toString( ( off % 3600 ) / 60, p, min ); - size_t minPos = basePos + 4; - - // - // assumes that point values for 0-9 are same between char and wchar_t - // - for ( size_t j = min.length(); j-- > 0; ) - { - s[minPos--] = min[j]; + if( min.size() == 1 ){ + s.push_back( '0' ); } + s.append(min); } } }; diff --git a/src/main/cpp/timezone.cpp b/src/main/cpp/timezone.cpp index a5ea9067..0169a80a 100644 --- a/src/main/cpp/timezone.cpp +++ b/src/main/cpp/timezone.cpp @@ -240,6 +240,13 @@ const TimeZonePtr TimeZone::getTimeZone( const LogString& id ) hours = StringHelper::toInt(off); } + // Make sure that our offset can't be crazy + if( hours > 14 ){ + hours = 14; + }else if( hours < -12 ){ + hours = -12; + } + LogString s(gmt); Pool p; LogString hh;
