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

Side by Side Diff: runtime/vm/native_message_handler.cc

Issue 10829444: Avoid trusting the length encoded in the Snapshot if there is an (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/native_message_handler.h" 5 #include "vm/native_message_handler.h"
6 6
7 #include "vm/dart_api_message.h" 7 #include "vm/dart_api_message.h"
8 #include "vm/isolate.h" 8 #include "vm/isolate.h"
9 #include "vm/message.h" 9 #include "vm/message.h"
10 #include "vm/snapshot.h" 10 #include "vm/snapshot.h"
(...skipping 28 matching lines...) Expand all
39 ApiZone* zone = ApiNativeScope::Current()->zone(); 39 ApiZone* zone = ApiNativeScope::Current()->zone();
40 return zone->Realloc<uint8_t>(ptr, old_size, new_size); 40 return zone->Realloc<uint8_t>(ptr, old_size, new_size);
41 } 41 }
42 42
43 43
44 bool NativeMessageHandler::HandleMessage(Message* message) { 44 bool NativeMessageHandler::HandleMessage(Message* message) {
45 if (message->IsOOB()) { 45 if (message->IsOOB()) {
46 // We currently do not use OOB messages for native ports. 46 // We currently do not use OOB messages for native ports.
47 UNREACHABLE(); 47 UNREACHABLE();
48 } 48 }
49
50 const Snapshot* snapshot = Snapshot::SetupFromBuffer(message->data(),
51 message->len());
52 if (snapshot == NULL || !snapshot->IsMessageSnapshot()) {
53 if (message->IsLocal()) {
54 FATAL("NativeMessageHandler saw malformed message. Exiting.");
55 }
56 delete message;
57 return true;
58 }
59
49 // Enter a native scope for handling the message. This will create a 60 // Enter a native scope for handling the message. This will create a
50 // zone for allocating the objects for decoding the message. 61 // zone for allocating the objects for decoding the message.
51 ApiNativeScope scope; 62 ApiNativeScope scope;
52 63 ApiMessageReader reader(snapshot, zone_allocator);
53 int32_t length = reinterpret_cast<int32_t*>(
54 message->data())[Snapshot::kLengthIndex];
55 ApiMessageReader reader(message->data() + Snapshot::kHeaderSize,
56 length,
57 zone_allocator);
58 Dart_CObject* object = reader.ReadMessage(); 64 Dart_CObject* object = reader.ReadMessage();
59 (*func())(message->dest_port(), message->reply_port(), object); 65 (*func())(message->dest_port(), message->reply_port(), object);
60 delete message; 66 delete message;
61 return true; 67 return true;
62 } 68 }
63 69
64 } // namespace dart 70 } // namespace dart
OLDNEW
« runtime/vm/isolate.cc ('K') | « runtime/vm/message_test.cc ('k') | runtime/vm/port_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698