Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r62685 - trunk/boost/date_time/local_time
From: andrey.semashev_at_[hidden]
Date: 2010-06-09 15:29:49


Author: andysem
Date: 2010-06-09 15:29:47 EDT (Wed, 09 Jun 2010)
New Revision: 62685
URL: http://svn.boost.org/trac/boost/changeset/62685

Log:
Refs #4154. Added iterator validity checks. If TZ string is not valid, the time zone constructor throws instead of crashing.

Text files modified:
   trunk/boost/date_time/local_time/posix_time_zone.hpp | 21 ++++++++++++++-------
   1 files changed, 14 insertions(+), 7 deletions(-)

Modified: trunk/boost/date_time/local_time/posix_time_zone.hpp
==============================================================================
--- trunk/boost/date_time/local_time/posix_time_zone.hpp (original)
+++ trunk/boost/date_time/local_time/posix_time_zone.hpp 2010-06-09 15:29:47 EDT (Wed, 09 Jun 2010)
@@ -79,9 +79,7 @@
     typedef boost::tokenizer<char_separator_type,
                              typename string_type::const_iterator,
                              string_type> tokenizer_type;
- typedef typename boost::tokenizer<char_separator_type,
- typename string_type::const_iterator,
- string_type>::iterator tokenizer_iterator_type;
+ typedef typename tokenizer_type::iterator tokenizer_iterator_type;
 
     //! Construct from a POSIX time zone string
     posix_time_zone_base(const string_type& s) :
@@ -101,11 +99,20 @@
 #endif
       char_separator_type sep(sep_chars);
       tokenizer_type tokens(s, sep);
- tokenizer_iterator_type it = tokens.begin();
+ tokenizer_iterator_type it = tokens.begin(), end = tokens.end();
+ if (it == end)
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Could not parse time zone name"));
       calc_zone(*it++);
- if(has_dst_){
- string_type tmp_str = *it++;
- calc_rules(tmp_str, *it);
+ if(has_dst_)
+ {
+ if (it == end)
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Could not parse DST begin time"));
+ string_type dst_begin = *it++;
+
+ if (it == end)
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Could not parse DST end time"));
+ string_type dst_end = *it;
+ calc_rules(dst_begin, dst_end);
       }
     }
     virtual ~posix_time_zone_base() {};


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk