]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cls/hello: test large return buffer overflow
authorSage Weil <sage@redhat.com>
Tue, 24 Sep 2019 19:52:02 +0000 (14:52 -0500)
committerSage Weil <sage@redhat.com>
Wed, 25 Sep 2019 18:29:10 +0000 (13:29 -0500)
Signed-off-by: Sage Weil <sage@redhat.com>
src/cls/hello/cls_hello.cc
src/test/cls_hello/test_cls_hello.cc

index 880c97b122d93bb703d345c1b13d83bd5dc4d9a9..c301b96a301d54043eb0f68564bd956c2e439721 100644 (file)
@@ -165,6 +165,24 @@ static int write_return_data(cls_method_context_t hctx, bufferlist *in, bufferli
   return 42;
 }
 
+static int write_too_much_return_data(cls_method_context_t hctx, bufferlist *in, bufferlist *out)
+{
+  // make some change to the object
+  bufferlist attrbl;
+  attrbl.append("bar");
+  int r = cls_cxx_setxattr(hctx, "foo", &attrbl);
+  if (r < 0)
+    return r;
+
+  // try to return too much data.  this should be enough to exceed
+  // osd_max_write_op_reply_len, which defaults to a pretty small number.
+  for (unsigned i=0; i < 10; ++i) {
+    out->append("you should not see this because it is toooooo long. ");
+  }
+
+  return 42;
+}
+
 
 /**
  * replay - a "read" method to get a previously recorded hello
@@ -299,6 +317,7 @@ CLS_INIT(hello)
   cls_method_handle_t h_record_hello;
   cls_method_handle_t h_replay;
   cls_method_handle_t h_write_return_data;
+  cls_method_handle_t h_write_too_much_return_data;
   cls_method_handle_t h_turn_it_to_11;
   cls_method_handle_t h_bad_reader;
   cls_method_handle_t h_bad_writer;
@@ -323,6 +342,9 @@ CLS_INIT(hello)
   cls_register_cxx_method(h_class, "write_return_data",
                          CLS_METHOD_WR,
                          write_return_data, &h_write_return_data);
+  cls_register_cxx_method(h_class, "write_too_much_return_data",
+                         CLS_METHOD_WR,
+                         write_too_much_return_data, &h_write_too_much_return_data);
   cls_register_cxx_method(h_class, "replay",
                          CLS_METHOD_RD,
                          replay, &h_replay);
index f37df635bbe7efdde0402f77ae1fb93bc508908b..74a713f2294238248d9c1281c6db2d5aa03aff95 100644 (file)
@@ -112,6 +112,22 @@ TEST(ClsHello, WriteReturnData) {
   out.hexdump(std::cout);
   ASSERT_EQ("you might see this", std::string(out.c_str(), out.length()));
 
+  // this will overflow because the return data is too big
+  {
+    in.clear();
+    out.clear();
+    int rval;
+    ObjectWriteOperation o;
+    o.exec("hello", "write_too_much_return_data", in, &out, &rval);
+    librados::AioCompletion *completion = cluster.aio_create_completion();
+    ASSERT_EQ(0, ioctx.aio_operate("foo", completion, &o,
+                                  librados::OPERATION_RETURNVEC));
+    completion->wait_for_safe();
+    ASSERT_EQ(-EOVERFLOW, completion->get_return_value());
+    ASSERT_EQ(-EOVERFLOW, rval);
+    ASSERT_EQ("", std::string(out.c_str(), out.length()));
+  }
+
   ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
 }