Opened 9 years ago

Closed 9 years ago

#9216 closed Bugs (fixed)

format_date_parser::parse_date reads off end of format_str if it ends with a %

Reported by: Roger Orr <rogero@…> Owned by: Marshall Clow
Milestone: To Be Determined Component: date_time
Version: Boost 1.54.0 Severity: Problem
Keywords: Cc:

Description

If boost::format_date_parser::parse_date is given a format_str such as "%" then the loop in date_time\format_date_parser.hpp:

    while (itr != format_str.end() && (sitr != stream_end)) {
      if (*itr == '%') {
        itr++;
        if (*itr != '%') { // <<< ERROR here
          switch(*itr) {
          case 'a': 

tries to dereference the one-past-the-end character on the line marked.

With a debugging iterator (eg MSVC) this causes runtime failure.

Change History (8)

comment:1 by Marshall Clow, 9 years ago

Owner: set to Marshall Clow

comment:2 by Marshall Clow, 9 years ago

Component: Nonedate_time
Status: newassigned

comment:3 by Marshall Clow, 9 years ago

Roger -

Can you make the following change to your local install and re-run your test?

       while (itr != format_str.end() && (sitr != stream_end)) {
      if (*itr == '%') {
-       itr++;
+       if ( ++itr == format_str.end()) break;
        if (*itr != '%') { // <<< ERROR here

Thanks!

comment:4 by Roger Orr <rogero@…>, 9 years ago

Thanks Marshall, I can confirm that making the code change fixes the specific problem. (I had hoped to have time to post a solution myself, but...)

However, I note that the same code pattern appears elsewhere in this header - in the

  • parse_month
  • parse_weekday
  • and parse_year

methods in this header file; and also in time_facet.hpp in two of the implementations of time_input_facet::get.

The same fix needs to be applied to these places too.

comment:5 by Marshall Clow, 9 years ago

Thanks Roger.

I had found the other three places in this file, but hadn't looked in other files - will check.

comment:6 by Marshall Clow, 9 years ago

(In [86230]) Fix several 'iterating past the end' bugs in Boost.DateTime; Refs #9216

comment:7 by Roger Orr <rogero@…>, 9 years ago

Thanks :-)

comment:8 by Marshall Clow, 9 years ago

Resolution: fixed
Status: assignedclosed

(In [86322]) Merge DateTime bug fix to Release; Fixes #9216

Note: See TracTickets for help on using tickets.