Make VhostUserMsgValidator use ByteValued

`extract_request_body()` assumes these types are POD as a safety
invariant, which is only possible if `VhostUserMsgValidator` is itself
an `unsafe trait` or depends on an `unsafe trait` with the correct
invariants.

`VhostUserMemoryRegion` is the only type that implemented
`VhostUserMsgValidator` and did not yet implement `ByteValued`

Signed-off-by: Manish Goregaokar <manishsmail@gmail.com>
This commit is contained in:
Manish Goregaokar 2023-08-23 13:10:27 -07:00 committed by Stefano Garzarella
parent 6ca88e160a
commit 10bf1e9123

View file

@ -203,7 +203,7 @@ impl Req for SlaveReq {
}
/// Vhost message Validator.
pub trait VhostUserMsgValidator {
pub trait VhostUserMsgValidator: ByteValued {
/// Validate message syntax only.
/// It doesn't validate message semantics such as protocol version number and dependency
/// on feature flags etc.
@ -594,6 +594,9 @@ impl VhostUserMemoryRegion {
}
}
// SAFETY: Safe because all fields of VhostUserMemoryRegion are POD.
unsafe impl ByteValued for VhostUserMemoryRegion {}
impl VhostUserMsgValidator for VhostUserMemoryRegion {
fn is_valid(&self) -> bool {
self.is_valid()