Author: gsim
Date: Fri Apr 13 23:36:26 2012
New Revision: 1326014

URL: http://svn.apache.org/viewvc?rev=1326014&view=rev
Log:
Bounds checking for str8/str16 on creating AMQP 0-10 structs

Modified:
    qpid/trunk/qpid/cpp/rubygen/framing.0-10/structs.rb
    qpid/trunk/qpid/cpp/src/tests/MessagingSessionTests.cpp

Modified: qpid/trunk/qpid/cpp/rubygen/framing.0-10/structs.rb
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/rubygen/framing.0-10/structs.rb?rev=1326014&r1=1326013&r2=1326014&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/rubygen/framing.0-10/structs.rb (original)
+++ qpid/trunk/qpid/cpp/rubygen/framing.0-10/structs.rb Fri Apr 13 23:36:26 2012
@@ -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;
 

Modified: qpid/trunk/qpid/cpp/src/tests/MessagingSessionTests.cpp
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/tests/MessagingSessionTests.cpp?rev=1326014&r1=1326013&r2=1326014&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/tests/MessagingSessionTests.cpp (original)
+++ qpid/trunk/qpid/cpp/src/tests/MessagingSessionTests.cpp Fri Apr 13 23:36:26 
2012
@@ -1139,6 +1139,13 @@ QPID_AUTO_TEST_CASE(testHeadersExchange)
     }
 }
 
+QPID_AUTO_TEST_CASE(testLargeRoutingKey)
+{
+    MessagingFixture fix;
+    std::string address = "amq.direct/" + std::string(300, 
'x');//routing/binding key can be at most 225 chars in 0-10
+    BOOST_CHECK_THROW(fix.session.createReceiver(address), 
qpid::messaging::MessagingException);
+}
+
 QPID_AUTO_TEST_SUITE_END()
 
 }} // namespace qpid::tests



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to