Merge changes I8d0c60e5,Ib8ad0ad6 am: a6bb369cb0 am: c7d9eb8636 am: a1c2561863

am: fb37f521b0

Change-Id: Ib67fcd1ff88df4e379ce92693eaa339d2dad0fbb
This commit is contained in:
Josh Gao 2017-05-23 03:00:18 +00:00 committed by android-build-merger
commit 8b4f5d97ce
5 changed files with 22 additions and 25 deletions

View file

@ -125,6 +125,11 @@ int adb_server_main(int is_daemon, const std::string& socket_spec, int ack_reply
});
#endif
if (is_daemon) {
close_stdin();
setup_daemon_logging();
}
android::base::at_quick_exit(adb_server_cleanup);
init_transport_registration();
@ -148,11 +153,6 @@ int adb_server_main(int is_daemon, const std::string& socket_spec, int ack_reply
std::this_thread::sleep_for(100ms);
}
if (is_daemon) {
close_stdin();
setup_daemon_logging();
}
adb_auth_init();
if (is_daemon) {

View file

@ -1050,27 +1050,24 @@ void unregister_usb_transport(usb_handle* usb) {
[usb](atransport* t) { return t->usb == usb && t->GetConnectionState() == kCsNoPerm; });
}
int check_header(apacket* p, atransport* t) {
bool check_header(apacket* p, atransport* t) {
if (p->msg.magic != (p->msg.command ^ 0xffffffff)) {
VLOG(RWX) << "check_header(): invalid magic command = " << std::hex << p->msg.command
<< ", magic = " << p->msg.magic;
return -1;
return false;
}
if (p->msg.data_length > t->get_max_payload()) {
VLOG(RWX) << "check_header(): " << p->msg.data_length
<< " atransport::max_payload = " << t->get_max_payload();
return -1;
return false;
}
return 0;
return true;
}
int check_data(apacket* p) {
if (calculate_apacket_checksum(p) != p->msg.data_check) {
return -1;
}
return 0;
bool check_data(apacket* p) {
return calculate_apacket_checksum(p) == p->msg.data_check;
}
#if ADB_HOST

View file

@ -221,8 +221,8 @@ int register_socket_transport(int s, const char* serial, int port, int local);
// This should only be used for transports with connection_state == kCsNoPerm.
void unregister_usb_transport(usb_handle* usb);
int check_header(apacket* p, atransport* t);
int check_data(apacket* p);
bool check_header(apacket* p, atransport* t);
bool check_data(apacket* p);
void close_usb_devices();
void close_usb_devices(std::function<bool(const atransport*)> predicate);

View file

@ -62,22 +62,22 @@ static atransport* local_transports[ ADB_LOCAL_TRANSPORT_MAX ];
static int remote_read(apacket *p, atransport *t)
{
if(!ReadFdExactly(t->sfd, &p->msg, sizeof(amessage))){
if (!ReadFdExactly(t->sfd, &p->msg, sizeof(amessage))) {
D("remote local: read terminated (message)");
return -1;
}
if(check_header(p, t)) {
if (!check_header(p, t)) {
D("bad header: terminated (data)");
return -1;
}
if(!ReadFdExactly(t->sfd, p->data, p->msg.data_length)){
if (!ReadFdExactly(t->sfd, p->data, p->msg.data_length)) {
D("remote local: terminated (data)");
return -1;
}
if(check_data(p)) {
if (!check_data(p)) {
D("bad data: terminated (data)");
return -1;
}

View file

@ -72,7 +72,7 @@ static int remote_read(apacket* p, atransport* t) {
D("remote usb: read terminated (message)");
return -1;
}
if (static_cast<size_t>(n) != sizeof(p->msg) || check_header(p, t)) {
if (static_cast<size_t>(n) != sizeof(p->msg) || !check_header(p, t)) {
D("remote usb: check_header failed, skip it");
goto err_msg;
}
@ -95,7 +95,7 @@ static int remote_read(apacket* p, atransport* t) {
goto err_msg;
}
}
if (check_data(p)) {
if (!check_data(p)) {
D("remote usb: check_data failed, skip it");
goto err_msg;
}
@ -124,19 +124,19 @@ static int remote_read(apacket *p, atransport *t)
return -1;
}
if(check_header(p, t)) {
if (!check_header(p, t)) {
D("remote usb: check_header failed");
return -1;
}
if(p->msg.data_length) {
if (p->msg.data_length) {
if (usb_read(t->usb, p->data, p->msg.data_length)) {
D("remote usb: terminated (data)");
return -1;
}
}
if(check_data(p)) {
if (!check_data(p)) {
D("remote usb: check_data failed");
return -1;
}