summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
authorGordon Sim <gsim@apache.org>2007-11-12 16:12:13 +0000
committerGordon Sim <gsim@apache.org>2007-11-12 16:12:13 +0000
commit8335a1bbe8a190158c18f7fee128c00e01ee6aa6 (patch)
treeb5d36f261d0072878e1bd09e7704c8f0311b2c6d /cpp/src
parentdf5ec6f74a070a5e6f67168124839b6c638ef918 (diff)
downloadqpid-python-8335a1bbe8a190158c18f7fee128c00e01ee6aa6.tar.gz
Minimal bounds checking
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@594198 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/qpid/framing/Buffer.cpp4
-rw-r--r--cpp/src/qpid/framing/Buffer.h5
2 files changed, 9 insertions, 0 deletions
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);