mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-07-04 17:02:36 +00:00
tpm: handle short write
There is no guarantee that the write can send the whole buffer at once. In those rare occasions, we should return a sensible error. Signed-off-by: Wei Liu <liuwe@microsoft.com>
This commit is contained in:
parent
6e22f23831
commit
5646a917ff
|
@ -208,7 +208,7 @@ impl Emulator {
|
||||||
buf.extend(converted_req);
|
buf.extend(converted_req);
|
||||||
debug!("full Control request {:02X?}", buf);
|
debug!("full Control request {:02X?}", buf);
|
||||||
|
|
||||||
let _res = self.control_socket.write(&buf).map_err(|e| {
|
let written = self.control_socket.write(&buf).map_err(|e| {
|
||||||
Error::RunControlCmd(anyhow!(
|
Error::RunControlCmd(anyhow!(
|
||||||
"Failed while running {:02X?} Control Cmd. Error: {:?}",
|
"Failed while running {:02X?} Control Cmd. Error: {:?}",
|
||||||
cmd,
|
cmd,
|
||||||
|
@ -216,6 +216,13 @@ impl Emulator {
|
||||||
))
|
))
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
if written < buf.len() {
|
||||||
|
return Err(Error::RunControlCmd(anyhow!(
|
||||||
|
"Truncated write while running {:02X?} Control Cmd",
|
||||||
|
cmd,
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
// The largest response is 16 bytes so far.
|
// The largest response is 16 bytes so far.
|
||||||
if msg_len_out > 16 {
|
if msg_len_out > 16 {
|
||||||
return Err(Error::RunControlCmd(anyhow!(
|
return Err(Error::RunControlCmd(anyhow!(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user