OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stdint.h> | 5 #include <stdint.h> |
6 #include <stdio.h> | 6 #include <stdio.h> |
7 | 7 |
| 8 #include <limits> |
8 #include <sstream> | 9 #include <sstream> |
9 #include <string> | 10 #include <string> |
10 | 11 |
11 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
12 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
13 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
14 #include "base/threading/platform_thread.h" | 15 #include "base/threading/platform_thread.h" |
15 #include "ipc/ipc_test_base.h" | 16 #include "ipc/ipc_test_base.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
17 | 18 |
(...skipping 15 matching lines...) Expand all Loading... |
33 | 34 |
34 // Used to generate an ID for a message that should not exist. | 35 // Used to generate an ID for a message that should not exist. |
35 IPC_MESSAGE_CONTROL0(MsgUnhandled) | 36 IPC_MESSAGE_CONTROL0(MsgUnhandled) |
36 | 37 |
37 // ----------------------------------------------------------------------------- | 38 // ----------------------------------------------------------------------------- |
38 | 39 |
39 namespace { | 40 namespace { |
40 | 41 |
41 TEST(IPCMessageIntegrity, ReadBeyondBufferStr) { | 42 TEST(IPCMessageIntegrity, ReadBeyondBufferStr) { |
42 // This was BUG 984408. | 43 // This was BUG 984408. |
43 uint32_t v1 = kuint32max - 1; | 44 uint32_t v1 = std::numeric_limits<uint32_t>::max() - 1; |
44 int v2 = 666; | 45 int v2 = 666; |
45 IPC::Message m(0, 1, IPC::Message::PRIORITY_NORMAL); | 46 IPC::Message m(0, 1, IPC::Message::PRIORITY_NORMAL); |
46 EXPECT_TRUE(m.WriteInt(v1)); | 47 EXPECT_TRUE(m.WriteInt(v1)); |
47 EXPECT_TRUE(m.WriteInt(v2)); | 48 EXPECT_TRUE(m.WriteInt(v2)); |
48 | 49 |
49 base::PickleIterator iter(m); | 50 base::PickleIterator iter(m); |
50 std::string vs; | 51 std::string vs; |
51 EXPECT_FALSE(iter.ReadString(&vs)); | 52 EXPECT_FALSE(iter.ReadString(&vs)); |
52 } | 53 } |
53 | 54 |
54 TEST(IPCMessageIntegrity, ReadBeyondBufferStr16) { | 55 TEST(IPCMessageIntegrity, ReadBeyondBufferStr16) { |
55 // This was BUG 984408. | 56 // This was BUG 984408. |
56 uint32_t v1 = kuint32max - 1; | 57 uint32_t v1 = std::numeric_limits<uint32_t>::max() - 1; |
57 int v2 = 777; | 58 int v2 = 777; |
58 IPC::Message m(0, 1, IPC::Message::PRIORITY_NORMAL); | 59 IPC::Message m(0, 1, IPC::Message::PRIORITY_NORMAL); |
59 EXPECT_TRUE(m.WriteInt(v1)); | 60 EXPECT_TRUE(m.WriteInt(v1)); |
60 EXPECT_TRUE(m.WriteInt(v2)); | 61 EXPECT_TRUE(m.WriteInt(v2)); |
61 | 62 |
62 base::PickleIterator iter(m); | 63 base::PickleIterator iter(m); |
63 base::string16 vs; | 64 base::string16 vs; |
64 EXPECT_FALSE(iter.ReadString16(&vs)); | 65 EXPECT_FALSE(iter.ReadString16(&vs)); |
65 } | 66 } |
66 | 67 |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 // thrown out of sync by the extra argument. | 364 // thrown out of sync by the extra argument. |
364 msg = new MsgClassIS(3, base::ASCIIToUTF16("expect three")); | 365 msg = new MsgClassIS(3, base::ASCIIToUTF16("expect three")); |
365 sender()->Send(msg); | 366 sender()->Send(msg); |
366 EXPECT_TRUE(listener.ExpectMessage(3, MsgClassIS::ID)); | 367 EXPECT_TRUE(listener.ExpectMessage(3, MsgClassIS::ID)); |
367 | 368 |
368 EXPECT_TRUE(WaitForClientShutdown()); | 369 EXPECT_TRUE(WaitForClientShutdown()); |
369 DestroyChannel(); | 370 DestroyChannel(); |
370 } | 371 } |
371 | 372 |
372 } // namespace | 373 } // namespace |
OLD | NEW |