This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [Patch, libstdc++/63497] Avoid dereferencing invalid iterator in regex_executor
- From: Jonathan Wakely <jwakely at redhat dot com>
- To: Tim Shen <timshen at google dot com>
- Cc: libstdc++ <libstdc++ at gcc dot gnu dot org>, gcc-patches at gcc dot gnu dot org
- Date: Tue, 21 Oct 2014 11:25:45 +0100
- Subject: Re: [Patch, libstdc++/63497] Avoid dereferencing invalid iterator in regex_executor
- Authentication-results: sourceware.org; auth=none
- References: <CAG4ZjNm4bW1BYdjUy-f1ydw66c-j7W2oa=SWRsc7c2P2rD4Tqg at mail dot gmail dot com>
On 20/10/14 10:23 -0700, Tim Shen wrote:
Bootstrapped and tested.
Did you manage to produce a testcase that crashed on trunk?
@@ -407,25 +409,28 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _BiIter, typename _Alloc, typename _TraitsT,
bool __dfs_mode>
bool _Executor<_BiIter, _Alloc, _TraitsT, __dfs_mode>::
- _M_word_boundary(_State<_TraitsT>) const
+ _M_word_boundary(_State<_TraitsT>)
{
- // By definition.
- bool __ans = false;
- auto __pre = _M_current;
- --__pre;
- if (!(_M_at_begin() && _M_at_end()))
+ bool __left_is_word = false;
+ if (_M_current != _M_begin
+ || (_M_flags & regex_constants::match_prev_avail))
{
- if (_M_at_begin())
- __ans = _M_is_word(*_M_current)
- && !(_M_flags & regex_constants::match_not_bow);
- else if (_M_at_end())
- __ans = _M_is_word(*__pre)
- && !(_M_flags & regex_constants::match_not_eow);
- else
- __ans = _M_is_word(*_M_current)
- != _M_is_word(*__pre);
+ --_M_current;
+ if (_M_is_word(*_M_current))
+ __left_is_word = true;
+ ++_M_current;
Is it really necessary to modify _M_current here?
Couldn't you do:
auto __pre = _M_current;
if (_M_is_word(*--__pre))
__left_is_word = true;
Then the function could remain const, couldn't it?