Skip to content

Commit f96c81e

Browse files
committed
Call abort_with_code_and_message directly in case of format failure in panic handler to avoid any possible recursive panic
Signed-off-by: adamperlin <[email protected]>
1 parent 33450d3 commit f96c81e

File tree

1 file changed

+2
-8
lines changed
  • src/hyperlight_guest_bin/src

1 file changed

+2
-8
lines changed

src/hyperlight_guest_bin/src/lib.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -157,21 +157,15 @@ fn _panic_handler(info: &core::panic::PanicInfo) -> ! {
157157
let mut panic_buf_guard: MutexGuard<'_, FixedStringBuf<'static>> = PANIC_BUF.lock();
158158
let write_res = write!(panic_buf_guard, "{}", info);
159159
if let Err(_) = write_res {
160-
// reset the buffer to ensure there is space
161-
// for the new panic message below
162-
panic_buf_guard.reset();
163-
panic!("panic: message format failed");
160+
unsafe { abort_with_code_and_message(&[ErrorCode::UnknownError as u8], b"panic: message format failed\0".as_ptr() as *const i8)}
164161
}
165162

166163
// create a CStr from the underlying array in PANIC_BUF using the as_cstr method.
167164
// this wraps CStr::from_bytes_until_nul which takes a borrowed byte slice
168165
// and does not allocate.
169166
let c_string_res = panic_buf_guard.as_c_str();
170167
if let Err(_) = c_string_res {
171-
// reset the buffer here as well, to ensure there is space
172-
// in the buffer to write the new panic message below.
173-
panic_buf_guard.reset();
174-
panic!("panic: failed to convert to CStr");
168+
unsafe { abort_with_code_and_message(&[ErrorCode::UnknownError as u8], b"panic: failed to convert to CStr\0".as_ptr() as *const i8)}
175169
}
176170

177171
unsafe { abort_with_code_and_message(&[ErrorCode::UnknownError as u8], c_string_res.unwrap().as_ptr()) }

0 commit comments

Comments
 (0)