Skip to content

Commit

Permalink
Fix some empty vector references
Browse files Browse the repository at this point in the history
streams.h has some methods that can be tricked into dereferencing
null pointers or end() iterators. Fix this.

Github-Pull: #10250
Rebased-From: f478d98
  • Loading branch information
sipa authored and luke-jr committed Jun 5, 2017
1 parent a40d69e commit e23cef0
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/streams.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ class CDataStream

void insert(iterator it, std::vector<char>::const_iterator first, std::vector<char>::const_iterator last)
{
assert(last - first >= 0);
if (last == first) return;
assert(last - first > 0);
if (it == vch.begin() + nReadPos && (unsigned int)(last - first) <= nReadPos)
{
// special case for inserting at the front when there's room
Expand All @@ -261,7 +262,8 @@ class CDataStream

void insert(iterator it, const char* first, const char* last)
{
assert(last - first >= 0);
if (last == first) return;
assert(last - first > 0);
if (it == vch.begin() + nReadPos && (unsigned int)(last - first) <= nReadPos)
{
// special case for inserting at the front when there's room
Expand Down Expand Up @@ -339,6 +341,8 @@ class CDataStream

void read(char* pch, size_t nSize)
{
if (nSize == 0) return;

// Read from the beginning of the buffer
unsigned int nReadPosNext = nReadPos + nSize;
if (nReadPosNext >= vch.size())
Expand Down

0 comments on commit e23cef0

Please sign in to comment.