Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1330)

Unified Diff: mojo/public/cpp/bindings/tests/buffer_unittest.cc

Issue 229203003: Make mojo buffer allocators more robust. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Tidy a little. Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: mojo/public/cpp/bindings/tests/buffer_unittest.cc
diff --git a/mojo/public/cpp/bindings/tests/buffer_unittest.cc b/mojo/public/cpp/bindings/tests/buffer_unittest.cc
index 49753e1a27d576a2f1a77b4296fd6cf8f1a5172d..7ef7520f5aec054eea41cdebbb3c9e37e7c222d5 100644
--- a/mojo/public/cpp/bindings/tests/buffer_unittest.cc
+++ b/mojo/public/cpp/bindings/tests/buffer_unittest.cc
@@ -43,6 +43,14 @@ TEST(ScratchBufferTest, Basic) {
small = buf.Allocate(10);
EXPECT_TRUE(IsZero(small, 10));
EXPECT_TRUE(small >= &buf && small < (&buf + sizeof(buf)));
+
+ // And a request so large it will fail.
+ void* fail = buf.Allocate(std::numeric_limits<size_t>::max() - 1024u);
+ EXPECT_TRUE(!fail);
+
+ // And a request so large it will overflow and fail.
+ void* overflow = buf.Allocate(std::numeric_limits<size_t>::max() - 12u);
+ EXPECT_TRUE(!overflow);
}
// Tests that Buffer::current() returns the correct value.
@@ -125,6 +133,10 @@ TEST(FixedBufferTest, TooBig) {
// Move the cursor forward.
EXPECT_NE(reinterpret_cast<void*>(0), buf.Allocate(16));
+ // A lot too large.
+ EXPECT_EQ(reinterpret_cast<void*>(0),
+ buf.Allocate(std::numeric_limits<size_t>::max() - 1024u));
+
// A lot too large, leading to possible integer overflow.
EXPECT_EQ(reinterpret_cast<void*>(0),
buf.Allocate(std::numeric_limits<size_t>::max() - 8u));

Powered by Google App Engine
This is Rietveld 408576698