diff options
author | Benoit Foucher <benoit@zeroc.com> | 2002-08-09 16:08:09 +0000 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2002-08-09 16:08:09 +0000 |
commit | c9407255d47543b23ed0d5cb322c862051f08ffb (patch) | |
tree | b0d0847c9879b0ac7a44058eaa83aaf0037dc508 /cpp/src/Ice/BasicStream.cpp | |
parent | Added Ice application shutdown hook. Fixed IceBox to use Ice Application. (diff) | |
download | ice-c9407255d47543b23ed0d5cb322c862051f08ffb.tar.bz2 ice-c9407255d47543b23ed0d5cb322c862051f08ffb.tar.xz ice-c9407255d47543b23ed0d5cb322c862051f08ffb.zip |
Fixed a bug where we would move the buffer iterator beyond the buffer end.
Diffstat (limited to 'cpp/src/Ice/BasicStream.cpp')
-rw-r--r-- | cpp/src/Ice/BasicStream.cpp | 89 |
1 files changed, 47 insertions, 42 deletions
diff --git a/cpp/src/Ice/BasicStream.cpp b/cpp/src/Ice/BasicStream.cpp index 116ede02032..271ce95ad26 100644 --- a/cpp/src/Ice/BasicStream.cpp +++ b/cpp/src/Ice/BasicStream.cpp @@ -261,12 +261,12 @@ IceInternal::BasicStream::writeBlob(const vector<Byte>& v) void IceInternal::BasicStream::readBlob(vector<Byte>& v, Int sz) { - Container::iterator begin = i; - i += sz; - if(i > b.end()) + if(b.end() - i < sz) { throw UnmarshalOutOfBoundsException(__FILE__, __LINE__); } + Container::iterator begin = i; + i += sz; v.resize(sz); copy(begin, i, v.begin()); } @@ -296,12 +296,12 @@ IceInternal::BasicStream::read(vector<Byte>& v) { Int sz; readSize(sz); - Container::iterator begin = i; - i += sz; - if(i > b.end()) + if(b.end() - i < sz) { throw UnmarshalOutOfBoundsException(__FILE__, __LINE__); } + Container::iterator begin = i; + i += sz; v.resize(sz); copy(begin, i, v.begin()); } @@ -331,12 +331,12 @@ IceInternal::BasicStream::read(vector<bool>& v) { Int sz; readSize(sz); - Container::iterator begin = i; - i += sz; - if(i > b.end()) + if(b.end() - i < sz) { throw UnmarshalOutOfBoundsException(__FILE__, __LINE__); } + Container::iterator begin = i; + i += sz; v.resize(sz); copy(begin, i, v.begin()); } @@ -380,12 +380,12 @@ IceInternal::BasicStream::write(const vector<Short>& v) void IceInternal::BasicStream::read(Short& v) { - Container::iterator begin = i; - i += sizeof(Short); - if(i > b.end()) + if(b.end() - i < static_cast<int>(sizeof(Short))) { throw UnmarshalOutOfBoundsException(__FILE__, __LINE__); } + Container::iterator begin = i; + i += sizeof(Short); #ifdef ICE_UTIL_BIGENDIAN reverse_copy(begin, i, reinterpret_cast<Byte*>(&v)); #else @@ -398,12 +398,13 @@ IceInternal::BasicStream::read(vector<Short>& v) { Int sz; readSize(sz); - Container::iterator begin = i; - i += sz * sizeof(Short); - if(i > b.end()) + const int length = sz * static_cast<int>(sizeof(Short)); + if(b.end() - i < length) { throw UnmarshalOutOfBoundsException(__FILE__, __LINE__); } + Container::iterator begin = i; + i += length; v.resize(sz); if(sz > 0) { @@ -458,12 +459,12 @@ IceInternal::BasicStream::write(const vector<Int>& v) void IceInternal::BasicStream::read(Int& v) { - Container::iterator begin = i; - i += sizeof(Int); - if(i > b.end()) + if(b.end() - i < static_cast<int>(sizeof(Int))) { throw UnmarshalOutOfBoundsException(__FILE__, __LINE__); } + Container::iterator begin = i; + i += sizeof(Int); #ifdef ICE_UTIL_BIGENDIAN reverse_copy(begin, i, reinterpret_cast<Byte*>(&v)); #else @@ -476,12 +477,13 @@ IceInternal::BasicStream::read(vector<Int>& v) { Int sz; readSize(sz); - Container::iterator begin = i; - i += sz * sizeof(Int); - if(i > b.end()) + const int length = sz * static_cast<int>(sizeof(Int)); + if(b.end() - i < length) { throw UnmarshalOutOfBoundsException(__FILE__, __LINE__); } + Container::iterator begin = i; + i += length; v.resize(sz); if(sz > 0) { @@ -536,12 +538,12 @@ IceInternal::BasicStream::write(const vector<Long>& v) void IceInternal::BasicStream::read(Long& v) { - Container::iterator begin = i; - i += sizeof(Long); - if(i > b.end()) + if(b.end() - i < static_cast<int>(sizeof(Long))) { throw UnmarshalOutOfBoundsException(__FILE__, __LINE__); } + Container::iterator begin = i; + i += sizeof(Long); #ifdef ICE_UTIL_BIGENDIAN reverse_copy(begin, i, reinterpret_cast<Byte*>(&v)); #else @@ -554,12 +556,13 @@ IceInternal::BasicStream::read(vector<Long>& v) { Int sz; readSize(sz); - Container::iterator begin = i; - i += sz * sizeof(Long); - if(i > b.end()) + const int length = sz * static_cast<int>(sizeof(Long)); + if(b.end() - i < length) { throw UnmarshalOutOfBoundsException(__FILE__, __LINE__); } + Container::iterator begin = i; + i += length; v.resize(sz); if(sz > 0) { @@ -614,12 +617,12 @@ IceInternal::BasicStream::write(const vector<Float>& v) void IceInternal::BasicStream::read(Float& v) { - Container::iterator begin = i; - i += sizeof(Float); - if(i > b.end()) + if(b.end() - i < static_cast<int>(sizeof(Float))) { throw UnmarshalOutOfBoundsException(__FILE__, __LINE__); } + Container::iterator begin = i; + i += sizeof(Float); #ifdef ICE_UTIL_BIGENDIAN reverse_copy(begin, i, reinterpret_cast<Byte*>(&v)); #else @@ -632,12 +635,13 @@ IceInternal::BasicStream::read(vector<Float>& v) { Int sz; readSize(sz); - Container::iterator begin = i; - i += sz * sizeof(Float); - if(i > b.end()) + const int length = sz * static_cast<int>(sizeof(Float)); + if(b.end() - i < length) { throw UnmarshalOutOfBoundsException(__FILE__, __LINE__); } + Container::iterator begin = i; + i += length; v.resize(sz); if(sz > 0) { @@ -692,12 +696,12 @@ IceInternal::BasicStream::write(const vector<Double>& v) void IceInternal::BasicStream::read(Double& v) { - Container::iterator begin = i; - i += sizeof(Double); - if(i > b.end()) + if(b.end() - i < static_cast<int>(sizeof(Double))) { throw UnmarshalOutOfBoundsException(__FILE__, __LINE__); } + Container::iterator begin = i; + i += sizeof(Double); #ifdef ICE_UTIL_BIGENDIAN reverse_copy(begin, i, reinterpret_cast<Byte*>(&v)); #else @@ -710,12 +714,13 @@ IceInternal::BasicStream::read(vector<Double>& v) { Int sz; readSize(sz); - Container::iterator begin = i; - i += sz * sizeof(Double); - if(i > b.end()) + const int length = sz * static_cast<int>(sizeof(Double)); + if(b.end() - i < length) { throw UnmarshalOutOfBoundsException(__FILE__, __LINE__); } + Container::iterator begin = i; + i += length; v.resize(sz); if(sz > 0) { @@ -767,12 +772,12 @@ IceInternal::BasicStream::read(string& v) } else { - Container::iterator begin = i; - i += len; - if(i > b.end()) + if(b.end() - i < len) { throw UnmarshalOutOfBoundsException(__FILE__, __LINE__); } + Container::iterator begin = i; + i += len; v.resize(len); copy(begin, i, v.begin()); } |