Opened 7 years ago

Closed 6 years ago

#11792 closed Bugs (fixed)

Boost convert will dereference empty strings iterators

Reported by: anonymous Owned by: Vladimir Batov
Milestone: To Be Determined Component: convert
Version: Boost 1.59.0 Severity: Problem
Keywords: Cc:

Description

The dereference can be found in boost/convert/base.hpp:to_str_ (line 108 in boost 1.59.0).

        /**/ if (skipws_) for (; std::isspace(*range.begin()); ++range);
        else if (std::isspace(*range.begin())) return;

range should be checked to see if it is empty before it is dereferenced.

Change History (8)

comment:1 by anonymous, 7 years ago

I made a pull request here:

https://github.com/boostorg/convert/pull/22

Not sure if it's the right way to go about it (both doing a pull request and the proposed fix itself).

in reply to:  1 comment:2 by vbmail247@…, 7 years ago

Replying to anonymous:

I made a pull request here:

https://github.com/boostorg/convert/pull/22

Not sure if it's the right way to go about it (both doing a pull request and the proposed fix itself).

Yes, indeed. The code currently does not handle empty strings. Missed that. Thank you. Unfortunately, adding "if (str.empty())" only works for std::string when str_to_() was meant to support C strings and user strings as well. After a brief look the change will probably have to go to the cnv::range constructor specializations. Let me think about it. I'll address it ASAP.

Thank you, Vladimir.

comment:3 by anonymous, 7 years ago

Just corrected the problem. Checked it into "develop" and synced to the "master".

comment:4 by Brad Anderson <eco@…>, 7 years ago

I have one more issue I've hit using Boost Convert. I think I lack the metaprogramming skills to really understand what is going on. I'd love if someone could take a look. I've documented it here:

https://svn.boost.org/trac/boost/ticket/11800

comment:5 by Vladimir Batov <vbmail247@…>, 7 years ago

The previous fix still had a problem which unfortunately did not show up with gcc and clang. Namely, boost::cnv::cnvbase::str_to_() was potentially trying to dereference the end() iterator. If my memory serves me, MSVC is strict about it. gcc & clang are lenient in that regard so I did not catch it. Hopefully fixed that now. Will monitor in the regression tests.

comment:6 by viboes, 7 years ago

Component: Noneconvert
Owner: set to viboes

comment:7 by viboes, 6 years ago

Owner: changed from viboes to Vladimir Batov

comment:8 by Vladimir Batov, 6 years ago

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.