boostorg / boostorg/chrono

V2 input crash when offset is unspecified

Open
#43 1 comment 0 reactions 0 assignees View on GitHub
bug PR welcome
Dominant language
C++
Stars
20
Forks
58
PR merge metrics
No merged PRs in 30d

Description

The following simple program crashes (SIGSEGV) with Boost 1.71.0 when reaching `in >> tp`:

~~~ c++
#define BOOST_CHRONO_VERSION 2
#include
#include
#include // assert
#include // std::istringstream
#include // std::string

int main() {
namespace bc = boost::chrono;

std::istringstream in("2019-09-16 13:16:31.539"); // missing offset
// bc::timezone_io_saver tzs(in, bc::timezone::local); // try this as well
bc::system_clock::time_point tp;

in >> tp; // crashes with default format
assert(in.eof());
assert(in.fail());
assert(!in.bad());
return 0;
}
~~~

The following diff prevents the crash and fulfills the `assert`s:

~~~ c++
--- boost/chrono/io/time_point_io.hpp.orig 2019-08-14 14:02:21.000000000 +0200
+++ boost/chrono/io/time_point_io.hpp 2019-09-16 20:13:47.435303802 +0200
@@ -1152,6 +1152,11 @@ namespace boost
}
It i(is);
It eof;
+ if (i == eof)
+ {
+ err |= std::ios_base::failbit;
+ goto exit;
+ }
c = *i;
if (++i == eof || c != ' ')
{
~~~

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.