MachMessageServer::Interface implementations: minor cleanups.

R=rsesek@chromium.org

Review URL: https://codereview.chromium.org/799463003
This commit is contained in:
Mark Mentovai 2014-12-15 14:47:47 -05:00
Родитель dc22dc405d
Коммит 554e75422c
6 изменённых файлов: 27 добавлений и 22 удалений

Просмотреть файл

@ -261,14 +261,14 @@ kern_return_t ChildPortHandshake::HandleChildPortCheckIn(
mach_port_t port,
mach_msg_type_name_t right_type,
const mach_msg_trailer_t* trailer,
bool* destroy_complex_request) {
bool* destroy_request) {
DCHECK_EQ(child_port_, kMachPortNull);
if (token != token_) {
// If the tokens not correct, someones attempting to spoof the legitimate
// client.
LOG(WARNING) << "ignoring incorrect token";
*destroy_complex_request = true;
*destroy_request = true;
} else {
checked_in_ = true;
@ -279,12 +279,11 @@ kern_return_t ChildPortHandshake::HandleChildPortCheckIn(
// by base::mac::ScopedMachSendRight. It is invalid to store a receive
// right in that scoper.
LOG(WARNING) << "ignoring MACH_MSG_TYPE_PORT_RECEIVE";
*destroy_complex_request = true;
*destroy_request = true;
} else {
// Communicate the child port back to the RunServer().
// *destroy_complex_request is left at false, because RunServer() needs
// the right to remain intact. It gives ownership of the right to its
// caller.
// *destroy_request is left at false, because RunServer() needs the right
// to remain intact. It gives ownership of the right to its caller.
child_port_ = port;
}
}

Просмотреть файл

@ -137,7 +137,7 @@ class ChildPortHandshake : public ChildPortServer::Interface {
mach_port_t port,
mach_msg_type_name_t right_type,
const mach_msg_trailer_t* trailer,
bool* destroy_complex_request) override;
bool* destroy_request) override;
//! \brief Runs the client.
//!

Просмотреть файл

@ -97,16 +97,18 @@ bool ChildPortServer::MachMessageServerFunction(
destroy_complex_request);
return true;
}
}
SetMIGReplyError(out_header, MIG_BAD_ID);
return false;
default: {
SetMIGReplyError(out_header, MIG_BAD_ID);
return false;
}
}
}
std::set<mach_msg_id_t> ChildPortServer::MachMessageServerRequestIDs() {
const mach_msg_id_t request_ids[] = {kMachMessageIDChildPortCheckIn};
return std::set<mach_msg_id_t>(
&request_ids[0], &request_ids[arraysize(request_ids)]);
return std::set<mach_msg_id_t>(&request_ids[0],
&request_ids[arraysize(request_ids)]);
}
mach_msg_size_t ChildPortServer::MachMessageServerRequestSize() {

Просмотреть файл

@ -17,6 +17,8 @@
#include <mach/mach.h>
#include <set>
#include "base/basictypes.h"
#include "util/mach/child_port_types.h"
#include "util/mach/mach_message_server.h"
@ -45,7 +47,7 @@ class ChildPortServer : public MachMessageServer::Interface {
mach_port_t port,
mach_msg_type_name_t right_type,
const mach_msg_trailer_t* trailer,
bool* destroy_complex_request) = 0;
bool* destroy_request) = 0;
protected:
~Interface() {}

Просмотреть файл

@ -94,7 +94,7 @@ class MockChildPortServerInterface : public ChildPortServer::Interface {
mach_port_t port,
mach_msg_type_name_t right_type,
const mach_msg_trailer_t* trailer,
bool* destroy_complex_request));
bool* destroy_request));
};
TEST(ChildPortServer, MockChildPortCheckIn) {
@ -106,10 +106,10 @@ TEST(ChildPortServer, MockChildPortCheckIn) {
EXPECT_EQ(expect_request_ids, server.MachMessageServerRequestIDs());
ChildPortCheckInRequest request;
EXPECT_LE(request.Head.msgh_size, server.MachMessageServerRequestSize());
EXPECT_EQ(request.Head.msgh_size, server.MachMessageServerRequestSize());
MIGReply reply;
EXPECT_LE(sizeof(reply), server.MachMessageServerReplySize());
EXPECT_EQ(sizeof(reply), server.MachMessageServerReplySize());
EXPECT_CALL(server_interface,
HandleChildPortCheckIn(kServerLocalPort,
@ -121,12 +121,12 @@ TEST(ChildPortServer, MockChildPortCheckIn) {
.WillOnce(Return(MIG_NO_REPLY))
.RetiresOnSaturation();
bool destroy_complex_request = false;
bool destroy_request = false;
EXPECT_TRUE(server.MachMessageServerFunction(
reinterpret_cast<mach_msg_header_t*>(&request),
reinterpret_cast<mach_msg_header_t*>(&reply),
&destroy_complex_request));
EXPECT_FALSE(destroy_complex_request);
&destroy_request));
EXPECT_FALSE(destroy_request);
reply.Verify();
}

Просмотреть файл

@ -476,10 +476,12 @@ bool ExcServer<Traits>::MachMessageServerFunction(
sizeof(out_reply->new_state[0]) * out_reply->new_stateCnt;
return true;
}
}
SetMIGReplyError(out_header, MIG_BAD_ID);
return false;
default: {
SetMIGReplyError(out_header, MIG_BAD_ID);
return false;
}
}
}
//! \brief A server interface for the `exc` or `mach_exc` Mach subsystems,