Fix uninitialized comparison in buffers iterator

fix #1263
This commit is contained in:
Vinnie Falco
2018-10-29 19:58:05 -07:00
parent 093af24e2b
commit 30ca9c59d3
7 changed files with 108 additions and 34 deletions

View File

@ -2,6 +2,7 @@ Version 187:
* Add experimental timeout_socket * Add experimental timeout_socket
* Fix warning in file tests * Fix warning in file tests
* Fix uninitialized comparison in buffers iterator
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------

View File

@ -31,6 +31,8 @@
* ([issue 1267]) Fix parsing of out-of-bounds hex values * ([issue 1267]) Fix parsing of out-of-bounds hex values
* ([issue 1263]) Fix uninitialized comparison in buffers iterator
* Workaround for http-server-fast and libstdc++ * Workaround for http-server-fast and libstdc++
[*Experimental] [*Experimental]

View File

@ -69,6 +69,8 @@ class buffers_adapter
{ {
} }
iter_type end_impl() const;
public: public:
/// The type of the underlying mutable buffer sequence /// The type of the underlying mutable buffer sequence
using value_type = MutableBufferSequence; using value_type = MutableBufferSequence;

View File

@ -26,7 +26,7 @@ template<class MutableBufferSequence>
class buffers_adapter<MutableBufferSequence>:: class buffers_adapter<MutableBufferSequence>::
const_buffers_type const_buffers_type
{ {
buffers_adapter const* ba_; buffers_adapter const* b_;
public: public:
using value_type = boost::asio::const_buffer; using value_type = boost::asio::const_buffer;
@ -48,8 +48,8 @@ public:
private: private:
friend class buffers_adapter; friend class buffers_adapter;
const_buffers_type(buffers_adapter const& ba) const_buffers_type(buffers_adapter const& b)
: ba_(&ba) : b_(&b)
{ {
} }
}; };
@ -59,7 +59,7 @@ class buffers_adapter<MutableBufferSequence>::
const_buffers_type::const_iterator const_buffers_type::const_iterator
{ {
iter_type it_; iter_type it_;
buffers_adapter const* ba_ = nullptr; buffers_adapter const* b_ = nullptr;
public: public:
using value_type = boost::asio::const_buffer; using value_type = boost::asio::const_buffer;
@ -78,8 +78,20 @@ public:
bool bool
operator==(const_iterator const& other) const operator==(const_iterator const& other) const
{ {
return ba_ == other.ba_ && return
it_ == other.it_; (b_ == nullptr) ?
(
other.b_ == nullptr ||
other.it_ == other.b_->end_impl()
):(
(other.b_ == nullptr) ?
(
it_ == b_->end_impl()
): (
b_ == other.b_ &&
it_ == other.it_
)
);
} }
bool bool
@ -93,9 +105,9 @@ public:
{ {
value_type const b = *it_; value_type const b = *it_;
return value_type{b.data(), return value_type{b.data(),
(ba_->out_ == boost::asio::buffer_sequence_end(ba_->bs_) || (b_->out_ == boost::asio::buffer_sequence_end(b_->bs_) ||
it_ != ba_->out_) ? b.size() : ba_->out_pos_} + it_ != b_->out_) ? b.size() : b_->out_pos_} +
(it_ == ba_->begin_ ? ba_->in_pos_ : 0); (it_ == b_->begin_ ? b_->in_pos_ : 0);
} }
pointer pointer
@ -134,33 +146,30 @@ public:
private: private:
friend class const_buffers_type; friend class const_buffers_type;
const_iterator(buffers_adapter const& ba, const_iterator(buffers_adapter const& b,
iter_type iter) iter_type iter)
: it_(iter) : it_(iter)
, ba_(&ba) , b_(&b)
{ {
} }
}; };
template<class MutableBufferSequence> template<class MutableBufferSequence>
inline
auto auto
buffers_adapter<MutableBufferSequence>:: buffers_adapter<MutableBufferSequence>::
const_buffers_type::begin() const -> const_buffers_type::begin() const ->
const_iterator const_iterator
{ {
return const_iterator{*ba_, ba_->begin_}; return const_iterator{*b_, b_->begin_};
} }
template<class MutableBufferSequence> template<class MutableBufferSequence>
inline
auto auto
buffers_adapter<MutableBufferSequence>:: buffers_adapter<MutableBufferSequence>::
const_buffers_type::end() const -> const_buffers_type::end() const ->
const_iterator const_iterator
{ {
return const_iterator{*ba_, ba_->out_ == return const_iterator{*b_, b_->end_impl()};
ba_->end_ ? ba_->end_ : std::next(ba_->out_)};
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -169,7 +178,7 @@ template<class MutableBufferSequence>
class buffers_adapter<MutableBufferSequence>:: class buffers_adapter<MutableBufferSequence>::
mutable_buffers_type mutable_buffers_type
{ {
buffers_adapter const* ba_; buffers_adapter const* b_;
public: public:
using value_type = boost::asio::mutable_buffer; using value_type = boost::asio::mutable_buffer;
@ -192,8 +201,8 @@ private:
friend class buffers_adapter; friend class buffers_adapter;
mutable_buffers_type( mutable_buffers_type(
buffers_adapter const& ba) buffers_adapter const& b)
: ba_(&ba) : b_(&b)
{ {
} }
}; };
@ -203,7 +212,7 @@ class buffers_adapter<MutableBufferSequence>::
mutable_buffers_type::const_iterator mutable_buffers_type::const_iterator
{ {
iter_type it_; iter_type it_;
buffers_adapter const* ba_ = nullptr; buffers_adapter const* b_ = nullptr;
public: public:
using value_type = boost::asio::mutable_buffer; using value_type = boost::asio::mutable_buffer;
@ -222,8 +231,20 @@ public:
bool bool
operator==(const_iterator const& other) const operator==(const_iterator const& other) const
{ {
return ba_ == other.ba_ && return
it_ == other.it_; (b_ == nullptr) ?
(
other.b_ == nullptr ||
other.it_ == other.b_->end_
):(
(other.b_ == nullptr) ?
(
it_ == b_->end_
): (
b_ == other.b_ &&
it_ == other.it_
)
);
} }
bool bool
@ -237,9 +258,9 @@ public:
{ {
value_type const b = *it_; value_type const b = *it_;
return value_type{b.data(), return value_type{b.data(),
it_ == std::prev(ba_->end_) ? it_ == std::prev(b_->end_) ?
ba_->out_end_ : b.size()} + b_->out_end_ : b.size()} +
(it_ == ba_->out_ ? ba_->out_pos_ : 0); (it_ == b_->out_ ? b_->out_pos_ : 0);
} }
pointer pointer
@ -278,10 +299,10 @@ public:
private: private:
friend class mutable_buffers_type; friend class mutable_buffers_type;
const_iterator(buffers_adapter const& ba, const_iterator(buffers_adapter const& b,
iter_type iter) iter_type iter)
: it_(iter) : it_(iter)
, ba_(&ba) , b_(&b)
{ {
} }
}; };
@ -294,7 +315,7 @@ mutable_buffers_type::
begin() const -> begin() const ->
const_iterator const_iterator
{ {
return const_iterator{*ba_, ba_->out_}; return const_iterator{*b_, b_->out_};
} }
template<class MutableBufferSequence> template<class MutableBufferSequence>
@ -305,11 +326,20 @@ mutable_buffers_type::
end() const -> end() const ->
const_iterator const_iterator
{ {
return const_iterator{*ba_, ba_->end_}; return const_iterator{*b_, b_->end_};
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
template<class MutableBufferSequence>
auto
buffers_adapter<MutableBufferSequence>::
end_impl() const ->
iter_type
{
return out_ == end_ ? end_ : std::next(out_);
}
template<class MutableBufferSequence> template<class MutableBufferSequence>
buffers_adapter<MutableBufferSequence>:: buffers_adapter<MutableBufferSequence>::
buffers_adapter(buffers_adapter&& other) buffers_adapter(buffers_adapter&& other)

View File

@ -281,9 +281,20 @@ buffers_cat_view<Bn...>::
const_iterator:: const_iterator::
operator==(const_iterator const& other) const operator==(const_iterator const& other) const
{ {
if(bn_ != other.bn_) return
return false; (bn_ == nullptr) ?
return it_ == other.it_; (
other.bn_ == nullptr ||
other.it_.index() == sizeof...(Bn)
):(
(other.bn_ == nullptr) ?
(
it_.index() == sizeof...(Bn)
): (
bn_ == other.bn_ &&
it_ == other.it_
)
);
} }
template<class... Bn> template<class... Bn>

View File

@ -73,7 +73,20 @@ public:
bool bool
operator==(const_iterator const& other) const operator==(const_iterator const& other) const
{ {
return b_ == other.b_ && it_ == other.it_; return
(b_ == nullptr) ?
(
other.b_ == nullptr ||
other.it_ == other.b_->end_
):(
(other.b_ == nullptr) ?
(
it_ == b_->end_
): (
b_ == other.b_ &&
it_ == other.it_
)
);
} }
bool bool
@ -139,6 +152,8 @@ private:
} }
}; };
//------------------------------------------------------------------------------
template<class BufferSequence> template<class BufferSequence>
void void
buffers_prefix_view<BufferSequence>:: buffers_prefix_view<BufferSequence>::

View File

@ -54,7 +54,20 @@ public:
bool bool
operator==(const_iterator const& other) const operator==(const_iterator const& other) const
{ {
return b_ == other.b_ && it_ == other.it_; return
(b_ == nullptr) ?
(
other.b_ == nullptr ||
other.it_ == boost::asio::buffer_sequence_end(other.b_->bs_)
):(
(other.b_ == nullptr) ?
(
it_ == boost::asio::buffer_sequence_end(b_->bs_)
): (
b_ == other.b_ &&
it_ == other.it_
)
);
} }
bool bool