[gbinder] Handle out-of-range transaction codes. JB#42956

This commit is contained in:
Slava Monich 2021-04-16 17:04:34 +03:00
parent 5fa4cd03de
commit 38fd1e6dcb
2 changed files with 35 additions and 16 deletions

View File

@ -203,9 +203,15 @@ gbinder_client_transact_sync_reply2(
req = r->basic_req;
}
}
return api->sync_reply(obj->ipc, obj->handle, code, req, status);
if (req) {
return api->sync_reply(obj->ipc, obj->handle, code, req,
status);
} else {
GWARN("Unable to build empty request for tx code %u", code);
}
} else {
GDEBUG("Refusing to perform transaction with a dead object");
}
GDEBUG("Refusing to perform transaction with a dead object");
}
return NULL;
}
@ -230,10 +236,15 @@ gbinder_client_transact_sync_oneway2(
req = r->basic_req;
}
}
return api->sync_oneway(obj->ipc, obj->handle, code, req);
if (req) {
return api->sync_oneway(obj->ipc, obj->handle, code, req);
} else {
GWARN("Unable to build empty request for tx code %u", code);
}
} else {
GDEBUG("Refusing to perform transaction with a dead object");
return (-ESTALE);
}
GDEBUG("Refusing to perform transaction with a dead object");
return (-ESTALE);
}
return (-EINVAL);
}
@ -407,13 +418,6 @@ gbinder_client_transact(
GBinderRemoteObject* obj = self->remote;
if (G_LIKELY(!obj->dead)) {
GBinderClientTx* tx = g_slice_new0(GBinderClientTx);
tx->client = gbinder_client_ref(self);
tx->reply = reply;
tx->destroy = destroy;
tx->user_data = user_data;
if (!req) {
const GBinderClientIfaceRange* r = gbinder_client_find_range
(gbinder_client_cast(self), code);
@ -423,12 +427,22 @@ gbinder_client_transact(
req = r->basic_req;
}
}
if (req) {
GBinderClientTx* tx = g_slice_new0(GBinderClientTx);
return gbinder_ipc_transact(obj->ipc, obj->handle, code,
flags, req, gbinder_client_transact_reply,
gbinder_client_transact_destroy, tx);
tx->client = gbinder_client_ref(self);
tx->reply = reply;
tx->destroy = destroy;
tx->user_data = user_data;
return gbinder_ipc_transact(obj->ipc, obj->handle, code,
flags, req, gbinder_client_transact_reply,
gbinder_client_transact_destroy, tx);
} else {
GWARN("Unable to build empty request for tx code %u", code);
}
} else {
GDEBUG("Refusing to perform transaction with a dead object");
}
GDEBUG("Refusing to perform transaction with a dead object");
}
return 0;
}

View File

@ -139,6 +139,11 @@ test_interfaces(
g_assert_cmpstr(gbinder_client_interface2(client, 33), == ,"33");
g_assert(!gbinder_client_interface2(client, 34));
g_assert(!gbinder_client_new_request2(client, 34));
/* Those fail to allocate default request for out-of-range codes: */
g_assert(!gbinder_client_transact_sync_reply(client, 34, NULL, NULL));
g_assert_cmpint(gbinder_client_transact_sync_oneway(client, 34, NULL),
== ,-EINVAL);
g_assert(!gbinder_client_transact(client, 34, 0, NULL, NULL, NULL, NULL));
gbinder_client_unref(client);
/* Client with no interface info */