Skip to content

Commit a8d822c

Browse files
committed
fix(virtq): truncate error message so it fits completion
Signed-off-by: Tomasz Andrzejak <andreiltd@gmail.com>
1 parent afeebcd commit a8d822c

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

src/hyperlight_host/src/sandbox/outb.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,12 +268,23 @@ fn outb_virtq_call(
268268

269269
let name = call.function_name.clone();
270270
let args: Vec<ParameterValue> = call.parameters.unwrap_or(vec![]);
271-
let res = host_funcs
271+
272+
let registry = host_funcs
272273
.try_lock()
273-
.map_err(|e| HandleOutbError::LockFailed(file!(), line!(), e.to_string()))?
274+
.map_err(|e| HandleOutbError::LockFailed(file!(), line!(), e.to_string()))?;
275+
276+
let mut res = registry
274277
.call_host_function(&name, args)
275278
.map_err(|e| GuestError::new(ErrorCode::HostFunctionError, e.to_string()));
276279

280+
// Truncate oversized error messages so the serialized response
281+
// fits in the completion buffer the guest pre-allocated.
282+
if let Err(err) = &mut res
283+
&& err.message.len() > wc.capacity()
284+
{
285+
err.message.truncate(wc.capacity());
286+
}
287+
277288
// Serialize response: VirtqMsgHeader + FunctionCallResult
278289
let func_result = FunctionCallResult::new(res);
279290
let mut builder = flatbuffers::FlatBufferBuilder::new();

src/hyperlight_host/tests/integration_test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ fn guest_malloc_abort() {
536536
});
537537

538538
// allocate a vector (on heap) that is bigger than the heap
539-
let heap_size = 0x4000;
539+
let heap_size = 0x8000;
540540
let size_to_allocate = 0x10000;
541541
assert!(
542542
size_to_allocate > heap_size,
@@ -585,7 +585,7 @@ fn guest_outb_with_invalid_port_poisons_sandbox() {
585585

586586
#[test]
587587
fn guest_panic_no_alloc() {
588-
let heap_size = 0x4000;
588+
let heap_size = 0x8000;
589589

590590
let mut cfg = SandboxConfiguration::default();
591591
cfg.set_heap_size(heap_size);

0 commit comments

Comments
 (0)