| 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 "ipc/ipc_message.h" | 5 #include "ipc/ipc_message.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include <limits> | 9 #include <limits> |
| 10 | 10 |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "ipc/attachment_broker.h" |
| 14 #include "ipc/ipc_message_utils.h" | 15 #include "ipc/ipc_message_utils.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 17 |
| 17 // IPC messages for testing ---------------------------------------------------- | 18 // IPC messages for testing ---------------------------------------------------- |
| 18 | 19 |
| 19 #define IPC_MESSAGE_IMPL | 20 #define IPC_MESSAGE_IMPL |
| 20 #include "ipc/ipc_message_macros.h" | 21 #include "ipc/ipc_message_macros.h" |
| 21 | 22 |
| 22 #define IPC_MESSAGE_START TestMsgStart | 23 #define IPC_MESSAGE_START TestMsgStart |
| 23 | 24 |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 IPC::Message::FindNext(data_start, data_end, &next); | 142 IPC::Message::FindNext(data_start, data_end, &next); |
| 142 EXPECT_TRUE(next.message_found); | 143 EXPECT_TRUE(next.message_found); |
| 143 EXPECT_EQ(next.message_size, message.size()); | 144 EXPECT_EQ(next.message_size, message.size()); |
| 144 EXPECT_EQ(next.pickle_end, data_end); | 145 EXPECT_EQ(next.pickle_end, data_end); |
| 145 EXPECT_EQ(next.message_end, data_end); | 146 EXPECT_EQ(next.message_end, data_end); |
| 146 | 147 |
| 147 // Data range doesn't contain the entire message | 148 // Data range doesn't contain the entire message |
| 148 // (but contains the message header) | 149 // (but contains the message header) |
| 149 IPC::Message::FindNext(data_start, data_end - 1, &next); | 150 IPC::Message::FindNext(data_start, data_end - 1, &next); |
| 150 EXPECT_FALSE(next.message_found); | 151 EXPECT_FALSE(next.message_found); |
| 151 #if USE_ATTACHMENT_BROKER | 152 #if USE_ATTACHMENT_BROKER && defined(OS_MACOSX) && !defined(OS_IOS) |
| 152 EXPECT_EQ(next.message_size, 0u); | 153 EXPECT_EQ(next.message_size, 0u); |
| 153 #else | 154 #else |
| 154 EXPECT_EQ(next.message_size, message.size()); | 155 EXPECT_EQ(next.message_size, message.size()); |
| 155 #endif | 156 #endif |
| 156 | 157 |
| 157 // Data range doesn't contain the message header | 158 // Data range doesn't contain the message header |
| 158 // (but contains the pickle header) | 159 // (but contains the pickle header) |
| 159 IPC::Message::FindNext(data_start, | 160 IPC::Message::FindNext(data_start, |
| 160 data_start + sizeof(IPC::Message::Header) - 1, | 161 data_start + sizeof(IPC::Message::Header) - 1, |
| 161 &next); | 162 &next); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 177 | 178 |
| 178 const char* data_start = reinterpret_cast<const char*>(message.data()); | 179 const char* data_start = reinterpret_cast<const char*>(message.data()); |
| 179 const char* data_end = data_start + message.size(); | 180 const char* data_end = data_start + message.size(); |
| 180 | 181 |
| 181 IPC::Message::NextMessageInfo next; | 182 IPC::Message::NextMessageInfo next; |
| 182 | 183 |
| 183 // Payload size is negative (defeats 'start + size > end' check) | 184 // Payload size is negative (defeats 'start + size > end' check) |
| 184 message.header()->payload_size = static_cast<uint32_t>(-1); | 185 message.header()->payload_size = static_cast<uint32_t>(-1); |
| 185 IPC::Message::FindNext(data_start, data_end, &next); | 186 IPC::Message::FindNext(data_start, data_end, &next); |
| 186 EXPECT_FALSE(next.message_found); | 187 EXPECT_FALSE(next.message_found); |
| 187 #if USE_ATTACHMENT_BROKER | 188 #if USE_ATTACHMENT_BROKER && defined(OS_MACOSX) && !defined(OS_IOS) |
| 188 EXPECT_EQ(next.message_size, 0u); | 189 EXPECT_EQ(next.message_size, 0u); |
| 189 #else | 190 #else |
| 190 if (sizeof(size_t) > sizeof(uint32_t)) { | 191 if (sizeof(size_t) > sizeof(uint32_t)) { |
| 191 // No overflow, just insane message size | 192 // No overflow, just insane message size |
| 192 EXPECT_EQ(next.message_size, | 193 EXPECT_EQ(next.message_size, |
| 193 message.header()->payload_size + sizeof(IPC::Message::Header)); | 194 message.header()->payload_size + sizeof(IPC::Message::Header)); |
| 194 } else { | 195 } else { |
| 195 // Actual overflow, reported as max size_t | 196 // Actual overflow, reported as max size_t |
| 196 EXPECT_EQ(next.message_size, std::numeric_limits<size_t>::max()); | 197 EXPECT_EQ(next.message_size, std::numeric_limits<size_t>::max()); |
| 197 } | 198 } |
| 198 #endif | 199 #endif |
| 199 | 200 |
| 200 // Payload size is max positive integer (defeats size < 0 check, while | 201 // Payload size is max positive integer (defeats size < 0 check, while |
| 201 // still potentially causing overflow down the road). | 202 // still potentially causing overflow down the road). |
| 202 message.header()->payload_size = std::numeric_limits<int32_t>::max(); | 203 message.header()->payload_size = std::numeric_limits<int32_t>::max(); |
| 203 IPC::Message::FindNext(data_start, data_end, &next); | 204 IPC::Message::FindNext(data_start, data_end, &next); |
| 204 EXPECT_FALSE(next.message_found); | 205 EXPECT_FALSE(next.message_found); |
| 205 #if USE_ATTACHMENT_BROKER | 206 #if USE_ATTACHMENT_BROKER && defined(OS_MACOSX) && !defined(OS_IOS) |
| 206 EXPECT_EQ(next.message_size, 0u); | 207 EXPECT_EQ(next.message_size, 0u); |
| 207 #else | 208 #else |
| 208 EXPECT_EQ(next.message_size, | 209 EXPECT_EQ(next.message_size, |
| 209 message.header()->payload_size + sizeof(IPC::Message::Header)); | 210 message.header()->payload_size + sizeof(IPC::Message::Header)); |
| 210 #endif | 211 #endif |
| 211 } | 212 } |
| 212 | 213 |
| 213 namespace { | 214 namespace { |
| 214 | 215 |
| 215 class IPCMessageParameterTest : public testing::Test { | 216 class IPCMessageParameterTest : public testing::Test { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 /* TODO: handle sync IPCs | 280 /* TODO: handle sync IPCs |
| 280 TEST_F(IPCMessageParameterTest, Sync) { | 281 TEST_F(IPCMessageParameterTest, Sync) { |
| 281 std::string output; | 282 std::string output; |
| 282 TestMsgClassIS message(42, &output); | 283 TestMsgClassIS message(42, &output); |
| 283 EXPECT_TRUE(OnMessageReceived(message)); | 284 EXPECT_TRUE(OnMessageReceived(message)); |
| 284 EXPECT_TRUE(called_); | 285 EXPECT_TRUE(called_); |
| 285 EXPECT_EQ(output, std::string("out")); | 286 EXPECT_EQ(output, std::string("out")); |
| 286 }*/ | 287 }*/ |
| 287 | 288 |
| 288 } // namespace IPC | 289 } // namespace IPC |
| OLD | NEW |