* to the guest via the CTRUNC bit), unlike truncation
* in target_to_host_cmsg, which is a QEMU bug.
*/
- if (msg_controllen < sizeof(struct cmsghdr)) {
+ if (msg_controllen < sizeof(struct target_cmsghdr)) {
target_msgh->msg_flags |= tswap32(MSG_CTRUNC);
break;
}
}
target_cmsg->cmsg_type = tswap32(cmsg->cmsg_type);
- tgt_len = TARGET_CMSG_LEN(len);
-
/* Payload types which need a different size of payload on
* the target must adjust tgt_len here.
*/
break;
}
default:
+ tgt_len = len;
break;
}
- if (msg_controllen < tgt_len) {
+ if (msg_controllen < TARGET_CMSG_LEN(tgt_len)) {
target_msgh->msg_flags |= tswap32(MSG_CTRUNC);
- tgt_len = msg_controllen;
+ tgt_len = msg_controllen - sizeof(struct target_cmsghdr);
}
/* We must now copy-and-convert len bytes of payload
uint32_t *v = (uint32_t *)data;
uint32_t *t_int = (uint32_t *)target_data;
+ if (len != sizeof(uint32_t) ||
+ tgt_len != sizeof(uint32_t)) {
+ goto unimplemented;
+ }
__put_user(*v, t_int);
break;
}
struct errhdr_t *target_errh =
(struct errhdr_t *)target_data;
+ if (len != sizeof(struct errhdr_t) ||
+ tgt_len != sizeof(struct errhdr_t)) {
+ goto unimplemented;
+ }
__put_user(errh->ee.ee_errno, &target_errh->ee.ee_errno);
__put_user(errh->ee.ee_origin, &target_errh->ee.ee_origin);
__put_user(errh->ee.ee_type, &target_errh->ee.ee_type);
uint32_t *v = (uint32_t *)data;
uint32_t *t_int = (uint32_t *)target_data;
+ if (len != sizeof(uint32_t) ||
+ tgt_len != sizeof(uint32_t)) {
+ goto unimplemented;
+ }
__put_user(*v, t_int);
break;
}
struct errhdr6_t *target_errh =
(struct errhdr6_t *)target_data;
+ if (len != sizeof(struct errhdr6_t) ||
+ tgt_len != sizeof(struct errhdr6_t)) {
+ goto unimplemented;
+ }
__put_user(errh->ee.ee_errno, &target_errh->ee.ee_errno);
__put_user(errh->ee.ee_origin, &target_errh->ee.ee_origin);
__put_user(errh->ee.ee_type, &target_errh->ee.ee_type);
}
}
- target_cmsg->cmsg_len = tswapal(tgt_len);
- tgt_space = TARGET_CMSG_SPACE(len);
+ target_cmsg->cmsg_len = tswapal(TARGET_CMSG_LEN(tgt_len));
+ tgt_space = TARGET_CMSG_SPACE(tgt_len);
if (msg_controllen < tgt_space) {
tgt_space = msg_controllen;
}