Browse Source

Fix some empty vector references

streams.h has some methods that can be tricked into dereferencing
null pointers or end() iterators. Fix this.
tags/v0.15.1
Pieter Wuille 4 years ago
parent
commit
f478d98fe4
1 changed files with 6 additions and 2 deletions
  1. 6
    2
      src/streams.h

+ 6
- 2
src/streams.h View File

@@ -248,7 +248,8 @@ public:

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
@@ -261,7 +262,8 @@ public:

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
@@ -339,6 +341,8 @@ public:

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())

Loading…
Cancel
Save