diff options
| author | Kenneth Anthony Giusti <kgiusti@apache.org> | 2010-10-28 21:33:52 +0000 |
|---|---|---|
| committer | Kenneth Anthony Giusti <kgiusti@apache.org> | 2010-10-28 21:33:52 +0000 |
| commit | e5f27778179696429e4212611c6e5454e2a63e99 (patch) | |
| tree | 58597637361766aeba3bf863ef4534cc74756643 /cpp/src/qpid | |
| parent | 3caac30ac5a8c2be453c1224e010fafa60e17ebf (diff) | |
| download | qpid-python-e5f27778179696429e4212611c6e5454e2a63e99.tar.gz | |
QPID-2916: throw an exception when a data value cannot be encoded correctly as its type.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1028501 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid')
| -rw-r--r-- | cpp/src/qpid/acl/management-schema.xml | 4 | ||||
| -rw-r--r-- | cpp/src/qpid/amqp_0_10/Codecs.cpp | 20 | ||||
| -rw-r--r-- | cpp/src/qpid/framing/Buffer.cpp | 43 |
3 files changed, 47 insertions, 20 deletions
diff --git a/cpp/src/qpid/acl/management-schema.xml b/cpp/src/qpid/acl/management-schema.xml index f4637253d0..7f48a9be34 100644 --- a/cpp/src/qpid/acl/management-schema.xml +++ b/cpp/src/qpid/acl/management-schema.xml @@ -18,7 +18,7 @@ <class name="Acl"> <property name="brokerRef" type="objId" references="org.apache.qpid.broker:Broker" access="RO" index="y" parentRef="y"/> - <property name="policyFile" type="sstr" access="RO" desc="Name of the policy file"/> + <property name="policyFile" type="lstr" access="RO" desc="Name of the policy file"/> <property name="enforcingAcl" type="bool" access="RO" desc="Currently Enforcing ACL"/> <property name="transferAcl" type="bool" access="RO" desc="Any transfer ACL rules in force"/> <property name="lastAclLoad" type="absTime" access="RO" desc="Timestamp of last successful load of ACL"/> @@ -32,7 +32,7 @@ <arg name="arguments" type="map"/> <arg name="objectName" type="sstr"/> <arg name="objectType" type="sstr"/> - <arg name="reason" type="sstr"/> + <arg name="reason" type="lstr"/> <arg name="userId" type="sstr"/> </eventArguments> diff --git a/cpp/src/qpid/amqp_0_10/Codecs.cpp b/cpp/src/qpid/amqp_0_10/Codecs.cpp index abe6b2c7da..0fbe2a60b9 100644 --- a/cpp/src/qpid/amqp_0_10/Codecs.cpp +++ b/cpp/src/qpid/amqp_0_10/Codecs.cpp @@ -198,15 +198,21 @@ boost::shared_ptr<FieldValue> convertString(const std::string& value, const std: } else { return boost::shared_ptr<FieldValue>(new Var16Value(value, 0x90)); } - } else if (encoding == utf8 && !large) { + } else if (encoding == utf8) { + if (!large) return boost::shared_ptr<FieldValue>(new Str16Value(value)); - } else if (encoding == utf16 && !large) { - return boost::shared_ptr<FieldValue>(new Var16Value(value, 0x96)); - } else if (encoding == iso885915 && !large) { - return boost::shared_ptr<FieldValue>(new Var16Value(value, 0x94)); + throw Exception(QPID_MSG("Could not encode utf8 character string - too long (" << value.size() << " bytes)")); + } else if (encoding == utf16) { + if (!large) + return boost::shared_ptr<FieldValue>(new Var16Value(value, 0x96)); + throw Exception(QPID_MSG("Could not encode utf16 character string - too long (" << value.size() << " bytes)")); + } else if (encoding == iso885915) { + if (!large) + return boost::shared_ptr<FieldValue>(new Var16Value(value, 0x94)); + throw Exception(QPID_MSG("Could not encode iso-8859-15 character string - too long (" << value.size() << " bytes)")); } else { - //either the string is too large for the encoding in amqp 0-10, or the encoding was not recognised - QPID_LOG(warning, "Could not encode " << value.size() << " byte value as " << encoding << ", encoding as vbin32."); + // the encoding was not recognised + QPID_LOG(warning, "Unknown byte encoding: [" << encoding << "], encoding as vbin32."); return boost::shared_ptr<FieldValue>(new Var32Value(value, 0xa0)); } } diff --git a/cpp/src/qpid/framing/Buffer.cpp b/cpp/src/qpid/framing/Buffer.cpp index 051e7a2362..7506cdca7b 100644 --- a/cpp/src/qpid/framing/Buffer.cpp +++ b/cpp/src/qpid/framing/Buffer.cpp @@ -20,6 +20,7 @@ */ #include "qpid/framing/Buffer.h" #include "qpid/framing/FieldTable.h" +#include "qpid/Msg.h" #include <string.h> #include <boost/format.hpp> namespace qpid { @@ -211,17 +212,29 @@ uint64_t Buffer::getUInt<8>() { template <> void Buffer::putUInt<1>(uint64_t i) { - putOctet(i); + if (std::numeric_limits<uint8_t>::min() <= i && i <= std::numeric_limits<uint8_t>::max()) { + putOctet(i); + return; + } + throw Exception(QPID_MSG("Could not encode (" << i << ") as uint8_t.")); } template <> void Buffer::putUInt<2>(uint64_t i) { - putShort(i); + if (std::numeric_limits<uint16_t>::min() <= i && i <= std::numeric_limits<uint16_t>::max()) { + putShort(i); + return; + } + throw Exception(QPID_MSG("Could not encode (" << i << ") as uint16_t.")); } template <> void Buffer::putUInt<4>(uint64_t i) { - putLong(i); + if (std::numeric_limits<uint32_t>::min() <= i && i <= std::numeric_limits<uint32_t>::max()) { + putLong(i); + return; + } + throw Exception(QPID_MSG("Could not encode (" << i << ") as uint32_t.")); } template <> @@ -231,18 +244,26 @@ void Buffer::putUInt<8>(uint64_t i) { void Buffer::putShortString(const string& s){ size_t slen = s.length(); - uint8_t len = slen < 0x100 ? (uint8_t) slen : 0xFF; - putOctet(len); - s.copy(data + position, len); - position += len; + if (slen <= std::numeric_limits<uint8_t>::max()) { + uint8_t len = (uint8_t) slen; + putOctet(len); + s.copy(data + position, len); + position += len; + return; + } + throw Exception(QPID_MSG("Could not encode string of " << slen << " bytes as uint8_t string.")); } void Buffer::putMediumString(const string& s){ size_t slen = s.length(); - uint16_t len = slen < 0x10000 ? (uint16_t) slen : 0xFFFF; - putShort(len); - s.copy(data + position, len); - position += len; + if (slen <= std::numeric_limits<uint16_t>::max()) { + uint16_t len = (uint16_t) slen; + putShort(len); + s.copy(data + position, len); + position += len; + return; + } + throw Exception(QPID_MSG("Could not encode string of " << slen << " bytes as uint16_t string.")); } void Buffer::putLongString(const string& s){ |
