summaryrefslogtreecommitdiff
path: root/qpid/cpp/rubygen/framing.0-10
diff options
context:
space:
mode:
authorGordon Sim <gsim@apache.org>2012-04-13 23:36:26 +0000
committerGordon Sim <gsim@apache.org>2012-04-13 23:36:26 +0000
commit545d8779510990f1303717eb10a722edb532650a (patch)
treed81f7b5aad5f46f3b833032d6dcd5ed2a463a187 /qpid/cpp/rubygen/framing.0-10
parent8b62753eb03e78908e5fccbff5b57d4064ea7b57 (diff)
downloadqpid-python-545d8779510990f1303717eb10a722edb532650a.tar.gz
QPID-3947: Bounds checking for str8/str16 on creating AMQP 0-10 structs
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1326014 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/cpp/rubygen/framing.0-10')
-rwxr-xr-xqpid/cpp/rubygen/framing.0-10/structs.rb25
1 files changed, 22 insertions, 3 deletions
diff --git a/qpid/cpp/rubygen/framing.0-10/structs.rb b/qpid/cpp/rubygen/framing.0-10/structs.rb
index 0a1bb475c9..f93742e57e 100755
--- a/qpid/cpp/rubygen/framing.0-10/structs.rb
+++ b/qpid/cpp/rubygen/framing.0-10/structs.rb
@@ -185,6 +185,13 @@ class StructGen < CppGen
end
end
+ def check_field(f)
+ if (size = StringSizeMap[f.cpptype.encoded] and size < 4)
+ limit = 2 ** (size * 8)
+ genl "if (#{f.cppname}.size() >= #{limit}) throw IllegalArgumentException(\"Value for #{f.cppname} is too large\");"
+ end
+ end
+
def process_packed_fields(s)
s.fields.each { |f| yield f, s.fields.index(f) }
end
@@ -260,11 +267,16 @@ EOS
indent {
process_packed_fields(s) { |f, i| genl "set#{f.name.caps}(_#{f.cppname});" if f.type_ == "bit"}
process_packed_fields(s) { |f, i| genl "flags |= #{flag_mask(s, i)};" unless f.type_ == "bit"}
+ s.fields.each { |f| check_field(f) }
}
genl "}"
else
indent { gen s.fields.collect { |f| " #{f.cppname}(_#{f.cppname})" }.join(",\n") }
- genl "{}"
+ genl "{"
+ indent {
+ s.fields.each { |f| check_field(f) }
+ }
+ genl "}"
end
end
#default constructors:
@@ -298,6 +310,7 @@ EOS
indent {
genl "#{f.cppname} = _#{f.cppname};"
genl "flags |= #{flag_mask(s, i)};"
+ check_field(f)
}
genl "}"
genl "#{f.cpptype.ret} #{s.cppname}::get#{f.name.caps}() const { return #{f.cppname}; }"
@@ -329,6 +342,7 @@ EOS
indent {
genl "#{f.cppname} = _#{f.cppname};"
genl "flags |= #{flag_mask(s, i)};"
+ check_field(f)
}
genl "}"
genl "#{f.cpptype.ret} #{s.body_name}::get#{f.name.caps}() const { return #{f.cppname}; }"
@@ -364,7 +378,12 @@ EOS
end
def define_accessors(f)
- genl "void set#{f.name.caps}(#{f.cpptype.param} _#{f.cppname}) { #{f.cppname} = _#{f.cppname}; }"
+ genl "void set#{f.name.caps}(#{f.cpptype.param} _#{f.cppname}) {"
+ indent {
+ genl "#{f.cppname} = _#{f.cppname};"
+ check_field(f)
+ }
+ genl "}"
genl "#{f.cpptype.ret} get#{f.name.caps}() const { return #{f.cppname}; }"
if (f.cpptype.name == "FieldTable")
genl "#{f.cpptype.name}& get#{f.name.caps}() { return #{f.cppname}; }"
@@ -401,6 +420,7 @@ EOS
#include <ostream>
#include "qpid/framing/amqp_types_full.h"
+#include "qpid/framing/reply_exceptions.h"
#include "qpid/CommonImportExport.h"
namespace qpid {
@@ -466,7 +486,6 @@ EOS
gen <<EOS
#include "qpid/framing/#{classname}.h"
#include "qpid/framing/Buffer.h"
-#include "qpid/framing/reply_exceptions.h"
using namespace qpid::framing;