diff options
author | bbudge@chromium.org <bbudge@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-02 16:17:37 +0000 |
---|---|---|
committer | bbudge@chromium.org <bbudge@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-02 16:17:37 +0000 |
commit | e74d2d16a08da00e3db7f394c4e8e0ae81164ab6 (patch) | |
tree | 3cf1979f56c2a924f960db32d862d8a9ed4d92cc /ppapi/proxy/nacl_message_scanner.cc | |
parent | 7352d62043942bb42e92b75648bf47bc3349434d (diff) | |
download | chromium_src-e74d2d16a08da00e3db7f394c4e8e0ae81164ab6.zip chromium_src-e74d2d16a08da00e3db7f394c4e8e0ae81164ab6.tar.gz chromium_src-e74d2d16a08da00e3db7f394c4e8e0ae81164ab6.tar.bz2 |
Pepper: Fix 2 message rewriting issues in NaClMessageScanner.
1) Don't stop rewriting if a SerializedVar contains no handles. It's
possible a subsequent one could.
2) Stop rewriting if a resource reply message is found to contain no
handles. The message will be discarded at the end.
This was split out from the HandleConverter CL to make it more comprehensible.
tbr=dmichael@chromium.org
BUG=194304
Review URL: https://codereview.chromium.org/56923002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@232621 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/proxy/nacl_message_scanner.cc')
-rw-r--r-- | ppapi/proxy/nacl_message_scanner.cc | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/ppapi/proxy/nacl_message_scanner.cc b/ppapi/proxy/nacl_message_scanner.cc index c2aa9eb..f9a67c4 100644 --- a/ppapi/proxy/nacl_message_scanner.cc +++ b/ppapi/proxy/nacl_message_scanner.cc @@ -32,7 +32,9 @@ struct ScanningResults { // be less than or equal to handles.size(). After the scan it should be equal. int handle_index; // The rewritten message. This may be NULL, so all ScanParam overloads should - // check for NULL before writing to it. + // check for NULL before writing to it. In some cases, a ScanParam overload + // may set this to NULL when it can determine that there are no parameters + // that need conversion. (See the ResourceMessageReplyParams overload.) scoped_ptr<IPC::Message> new_msg; }; @@ -67,11 +69,7 @@ void HandleWriter(int* handle_index, void ScanParam(const ppapi::proxy::SerializedVar& var, ScanningResults* results) { std::vector<ppapi::proxy::SerializedHandle*> var_handles = var.GetHandles(); - // TODO(bbudge) Remove this early out, since a subsequent SerializedVar may - // contain handles, and we will have dropped this one's data. - if (var_handles.empty()) - return; - + // Copy any handles and then rewrite the message. for (size_t i = 0; i < var_handles.size(); ++i) results->handles.push_back(*var_handles[i]); if (results->new_msg) @@ -86,6 +84,15 @@ void ScanParam(const ppapi::proxy::SerializedVar& var, // ResourceMessageReplyParams, so that's the only one we need to handle. void ScanParam(const ppapi::proxy::ResourceMessageReplyParams& params, ScanningResults* results) { + // If the resource reply params don't contain handles, NULL the new message + // pointer to cancel further rewriting. + // NOTE: This works because only handles currently need rewriting, and we + // know at this point that this message has none. + if (params.handles().empty()) { + results->new_msg.reset(NULL); + return; + } + // If we need to rewrite the message, write everything before the handles // (there's nothing after the handles). if (results->new_msg) { @@ -230,8 +237,11 @@ bool NaClMessageScanner::ScanMessage( (msg.type() == PpapiMsg_CreateNaClChannel::ID); #endif + // We can't always tell from the message ID if rewriting is needed. Therefore, - // scan any message types that might contain a handle. + // scan any message types that might contain a handle. If we later determine + // that there are no handles, we can cancel the rewriting by clearing the + // results.new_msg pointer. ScanningResults results; switch (msg.type()) { CASE_FOR_MESSAGE(PpapiMsg_CreateNaClChannel) |