aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPieter Wuille <[email protected]>2017-04-13 02:33:04 -0700
committerLuke Dashjr <[email protected]>2017-06-05 22:58:23 +0000
commite23cef0c9469cc360e603a614bb3f0b22c6656bf (patch)
treee6a0ed0c3a1941ca0061f226e9f7533449746684 /src
parentMerge #10328 via branch 'debianppa-0.14' into 0.14.2_fixes (diff)
downloaddiscoin-e23cef0c9469cc360e603a614bb3f0b22c6656bf.tar.xz
discoin-e23cef0c9469cc360e603a614bb3f0b22c6656bf.zip
Fix some empty vector references
streams.h has some methods that can be tricked into dereferencing null pointers or end() iterators. Fix this. Github-Pull: #10250 Rebased-From: f478d98fe49d3c0c0f2c79b3f8d9dbfc1aafd407
Diffstat (limited to 'src')
-rw-r--r--src/streams.h8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/streams.h b/src/streams.h
index 1d3b55c91..e49a9e354 100644
--- a/src/streams.h
+++ b/src/streams.h
@@ -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())