From cb66c07a5f4c239db070a9830a8f97a6993ba81e Mon Sep 17 00:00:00 2001 From: Jcodefox Date: Fri, 1 Dec 2023 09:48:57 -0500 Subject: [PATCH] Add check for non-existent buffer --- kernel/src/holeybytes/ecah.rs | 27 +++++++++++++++------------ sysdata/test-programs/main.rhai | 3 ++- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/kernel/src/holeybytes/ecah.rs b/kernel/src/holeybytes/ecah.rs index b3f82a27..c43226bd 100644 --- a/kernel/src/holeybytes/ecah.rs +++ b/kernel/src/holeybytes/ecah.rs @@ -77,20 +77,23 @@ pub fn handler(vm: &mut Vm) { buffer_id => { let mut buffs = IPC_BUFFERS.lock(); - let mut buff = buffs.get_mut(&buffer_id).unwrap(); + match buffs.get_mut(&buffer_id) { + Some(buff) => { + let mut msg_vec = vec![]; - let mut msg_vec = vec![]; - - for x in 0..(length as isize) { - let xyz = mem_addr as *const u8; - let value = unsafe { xyz.offset(x).read() }; - msg_vec.push(value); + for x in 0..(length as isize) { + let xyz = mem_addr as *const u8; + let value = unsafe { xyz.offset(x).read() }; + msg_vec.push(value); + } + buff.push(msg_vec.clone()); + info!( + "Message {:?} has been sent to Buffer({})", + msg_vec, buffer_id + ); + } + None => log::error!("Access of non-existent buffer") } - buff.push(msg_vec.clone()); - info!( - "Message {:?} has been sent to Buffer({})", - msg_vec, buffer_id - ); drop(buffs); } } diff --git a/sysdata/test-programs/main.rhai b/sysdata/test-programs/main.rhai index 63a2f225..1875f365 100644 --- a/sysdata/test-programs/main.rhai +++ b/sysdata/test-programs/main.rhai @@ -8,8 +8,9 @@ fn main(){ std::Trace("Trace Deez"); std::ipc_send(2, 0, 0); + std::ipc_send(3, 0, 0); tx(); } -main(); \ No newline at end of file +main();