Skip to content

Commit

Permalink
IPC: make sure we return a consistent error when the message is too big.
Browse files Browse the repository at this point in the history
Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
  • Loading branch information
asalkeld committed Jan 25, 2013
1 parent 848242a commit dde6a46
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
10 changes: 8 additions & 2 deletions lib/ipcc.c
Expand Up @@ -132,9 +132,12 @@ qb_ipcc_send(struct qb_ipcc_connection * c, const void *msg_ptr, size_t msg_len)
ssize_t res;
ssize_t res2;

if (c == NULL || msg_len > c->request.max_msg_size) {
if (c == NULL) {
return -EINVAL;
}
if (msg_len > c->request.max_msg_size) {
return -EMSGSIZE;
}
if (c->funcs.fc_get) {
res = c->funcs.fc_get(&c->request);
if (res < 0) {
Expand Down Expand Up @@ -186,9 +189,12 @@ qb_ipcc_sendv(struct qb_ipcc_connection * c, const struct iovec * iov,
for (i = 0; i < iov_len; i++) {
total_size += iov[i].iov_len;
}
if (c == NULL || total_size > c->request.max_msg_size) {
if (c == NULL) {
return -EINVAL;
}
if (total_size > c->request.max_msg_size) {
return -EMSGSIZE;
}

if (c->funcs.fc_get) {
res = c->funcs.fc_get(&c->request);
Expand Down
4 changes: 4 additions & 0 deletions lib/ipcs.c
Expand Up @@ -367,6 +367,10 @@ qb_ipcs_event_send(struct qb_ipcs_connection * c, const void *data, size_t size)
}
qb_ipcs_connection_ref(c);

if (size > c->event.max_msg_size) {
return -EMSGSIZE;
}

res = c->service->funcs.send(&c->event, data, size);
if (res == size) {
c->stats.events++;
Expand Down
13 changes: 12 additions & 1 deletion tests/check_ipc.c
Expand Up @@ -127,6 +127,11 @@ s1_msg_process_fn(qb_ipcs_connection_t *c,
num = stats->event_q_length;
free(stats);

/* crazy large message */
res = qb_ipcs_event_send(c, &response,
MAX_MSG_SIZE*10);
ck_assert_int_eq(res, -EMSGSIZE);

for (m = 0; m < num_bulk_events; m++) {
res = qb_ipcs_event_send(c, &response,
sizeof(response));
Expand Down Expand Up @@ -292,6 +297,13 @@ send_and_check(int32_t req_id, uint32_t size,
request.hdr.id = req_id;
request.hdr.size = sizeof(struct qb_ipc_request_header) + size;

/* check that we can't send a message that is too big
* and we get the right return code.
*/
res = qb_ipcc_send(conn, &request, MAX_MSG_SIZE*2);
ck_assert_int_eq(res, -EMSGSIZE);


repeat_send:

res = qb_ipcc_send(conn, &request, request.hdr.size);
Expand Down Expand Up @@ -1008,4 +1020,3 @@ main(void)
srunner_free(sr);
return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}

0 comments on commit dde6a46

Please sign in to comment.