From 8335a1bbe8a190158c18f7fee128c00e01ee6aa6 Mon Sep 17 00:00:00 2001 From: Gordon Sim Date: Mon, 12 Nov 2007 16:12:13 +0000 Subject: Minimal bounds checking git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@594198 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/src/qpid/framing/Buffer.cpp | 4 ++++ cpp/src/qpid/framing/Buffer.h | 5 +++++ 2 files changed, 9 insertions(+) (limited to 'cpp/src') diff --git a/cpp/src/qpid/framing/Buffer.cpp b/cpp/src/qpid/framing/Buffer.cpp index eaa4433b5f..b42797414f 100644 --- a/cpp/src/qpid/framing/Buffer.cpp +++ b/cpp/src/qpid/framing/Buffer.cpp @@ -164,12 +164,14 @@ void Buffer::putLongString(const string& s){ void Buffer::getShortString(string& s){ uint8_t len = getOctet(); + checkAvailable(len); s.assign(data + position, len); position += len; } void Buffer::getLongString(string& s){ uint32_t len = getLong(); + checkAvailable(len); s.assign(data + position, len); position += len; } @@ -181,6 +183,7 @@ void Buffer::putRawData(const string& s){ } void Buffer::getRawData(string& s, uint32_t len){ + checkAvailable(len); s.assign(data + position, len); position += len; } @@ -191,6 +194,7 @@ void Buffer::putRawData(const uint8_t* s, size_t len){ } void Buffer::getRawData(uint8_t* s, size_t len){ + checkAvailable(len); memcpy(s, data + position, len); position += len; } diff --git a/cpp/src/qpid/framing/Buffer.h b/cpp/src/qpid/framing/Buffer.h index 190f736f46..fe33dbd366 100644 --- a/cpp/src/qpid/framing/Buffer.h +++ b/cpp/src/qpid/framing/Buffer.h @@ -19,6 +19,7 @@ * */ #include "amqp_types.h" +#include "qpid/Exception.h" #ifndef _Buffer_ #define _Buffer_ @@ -26,6 +27,8 @@ namespace qpid { namespace framing { +struct OutOfBounds : qpid::Exception {}; + class Content; class FieldTable; @@ -36,6 +39,8 @@ class Buffer uint32_t position; uint32_t r_position; + void checkAvailable(uint32_t count) { if (position + count > size) throw OutOfBounds(); } + public: Buffer(char* data, uint32_t size); -- cgit v1.2.1