From 4bc7cd704ad9856c389b4816d57bfd263dc49b37 Mon Sep 17 00:00:00 2001 From: Emmanuel Leblond Date: Wed, 7 Aug 2024 12:26:48 +0200 Subject: [PATCH] wip --- winfsp_wrs/src/callback.rs | 80 ++++++++++++++++++++++++++++++-------- 1 file changed, 64 insertions(+), 16 deletions(-) diff --git a/winfsp_wrs/src/callback.rs b/winfsp_wrs/src/callback.rs index a629239..5426045 100644 --- a/winfsp_wrs/src/callback.rs +++ b/winfsp_wrs/src/callback.rs @@ -703,7 +703,12 @@ impl TrampolineInterface { ) -> NTSTATUS { let fs = &*(*file_system).UserContext.cast::(); let fctx = C::FileContext::access(file_context); - let buffer = std::slice::from_raw_parts_mut(buffer.cast(), length as usize); + let buffer = if !buffer.is_null() { + std::slice::from_raw_parts_mut(buffer.cast(), length as usize) + } else { + &mut [] + }; + match C::read(fs, fctx, buffer, offset) { Ok(bytes_transferred) => { @@ -742,7 +747,11 @@ impl TrampolineInterface { ) -> NTSTATUS { let fs = &*(*file_system).UserContext.cast::(); let fctx = C::FileContext::access(file_context); - let buffer = std::slice::from_raw_parts(buffer.cast(), length as usize); + let buffer = if !buffer.is_null() { + std::slice::from_raw_parts(buffer.cast(), length as usize) + } else { + &[] + }; let mode = match (write_to_end_of_file != 0, constrained_io != 0) { (false, false) => WriteMode::Normal { offset }, @@ -1073,13 +1082,13 @@ impl TrampolineInterface { ) -> NTSTATUS { let fs = &*(*file_system).UserContext.cast::(); let file_name = U16CStr::from_ptr_str_mut(file_name); - let buffer = if buffer.is_null() { - None - } else { + let buffer = if !buffer.is_null() { Some(std::slice::from_raw_parts_mut( buffer.cast(), psize.read() as usize, )) + } else { + None }; match C::get_reparse_point_by_name(fs, file_name, is_directory != 0, buffer) { @@ -1151,7 +1160,11 @@ impl TrampolineInterface { let fs = &*(*file_system).UserContext.cast::(); let fctx = C::FileContext::access(file_context); let file_name = U16CStr::from_ptr_str(file_name); - let buffer = std::slice::from_raw_parts_mut(buffer.cast(), *p_size as usize); + let buffer = if !buffer.is_null() { + std::slice::from_raw_parts_mut(buffer.cast(), *p_size as usize) + } else { + &mut [] + }; match C::get_reparse_point(fs, fctx, file_name, buffer) { Ok(byte_transferred) => { @@ -1180,7 +1193,11 @@ impl TrampolineInterface { let fs = &*(*file_system).UserContext.cast::(); let fctx = C::FileContext::access(file_context); let file_name = U16CStr::from_ptr_str(file_name); - let buffer = std::slice::from_raw_parts_mut(buffer.cast(), size as usize); + let buffer = if !buffer.is_null() { + std::slice::from_raw_parts_mut(buffer.cast(), size as usize) + } else { + &mut [] + }; match C::set_reparse_point(fs, fctx, file_name, buffer) { Ok(()) => STATUS_SUCCESS, @@ -1204,7 +1221,11 @@ impl TrampolineInterface { let fs = &*(*file_system).UserContext.cast::(); let fctx = C::FileContext::access(file_context); let file_name = U16CStr::from_ptr_str(file_name); - let buffer = std::slice::from_raw_parts_mut(buffer.cast(), size as usize); + let buffer = if !buffer.is_null() { + std::slice::from_raw_parts_mut(buffer.cast(), size as usize) + } else { + &mut [] + }; match C::delete_reparse_point(fs, fctx, file_name, buffer) { Ok(()) => STATUS_SUCCESS, @@ -1229,7 +1250,11 @@ impl TrampolineInterface { ) -> NTSTATUS { let fs = &*(*file_system).UserContext.cast::(); let fctx = C::FileContext::access(file_context); - let buffer = std::slice::from_raw_parts_mut(buffer.cast(), length as usize); + let buffer = if !buffer.is_null() { + std::slice::from_raw_parts_mut(buffer.cast(), length as usize) + } else { + &mut [] + }; match C::get_stream_info(fs, fctx, buffer) { Ok(bytes_transferred) => { @@ -1299,9 +1324,16 @@ impl TrampolineInterface { ) -> NTSTATUS { let fs = &*(*file_system).UserContext.cast::(); let fctx = C::FileContext::access(file_context); - let input = std::slice::from_raw_parts(input_buffer.cast(), input_buffer_length as usize); - let output = - std::slice::from_raw_parts_mut(output_buffer.cast(), output_buffer_length as usize); + let input = if !input_buffer.is_null() { + std::slice::from_raw_parts(input_buffer.cast(), input_buffer_length as usize) + } else { + &[] + }; + let output = if !output_buffer.is_null() { + std::slice::from_raw_parts_mut(output_buffer.cast(), output_buffer_length as usize) + } else { + &mut [] + }; match C::control(fs, fctx, control_code, input, output) { Ok(bytes_transferred) => { @@ -1449,7 +1481,11 @@ impl TrampolineInterface { let fs = &*(*file_system).UserContext.cast::(); let file_name = U16CStr::from_ptr_str(file_name); let sd = SecurityDescriptor::from_ptr(security_descriptor); - let buffer = std::slice::from_raw_parts(extra_buffer.cast(), extra_length as usize); + let buffer = if !extra_buffer.is_null() { + std::slice::from_raw_parts(extra_buffer.cast(), extra_length as usize) + } else { + &[] + }; match C::create_ex( fs, @@ -1535,7 +1571,11 @@ impl TrampolineInterface { ) -> NTSTATUS { let fs = &*(*file_system).UserContext.cast::(); let fctx = C::FileContext::access(file_context); - let buffer = std::slice::from_raw_parts(ea.cast(), ea_length as usize); + let buffer = if !ea.is_null() { + std::slice::from_raw_parts(ea.cast(), ea_length as usize) + } else { + &[] + }; match C::overwrite_ex( fs, @@ -1570,7 +1610,11 @@ impl TrampolineInterface { ) -> NTSTATUS { let fs = &*(*file_system).UserContext.cast::(); let fctx = C::FileContext::access(file_context); - let buffer = std::slice::from_raw_parts(ea.cast(), ea_length as usize); + let buffer = if !ea.is_null() { + std::slice::from_raw_parts(ea.cast(), ea_length as usize) + } else { + &[] + }; match C::get_ea(fs, fctx, buffer) { Ok(bytes_transfered) => { @@ -1599,7 +1643,11 @@ impl TrampolineInterface { ) -> NTSTATUS { let fs = &*(*file_system).UserContext.cast::(); let fctx = C::FileContext::access(file_context); - let buffer = std::slice::from_raw_parts(ea.cast(), ea_length as usize); + let buffer = if !ea.is_null() { + std::slice::from_raw_parts(ea.cast(), ea_length as usize) + } else { + &[] + }; match C::set_ea(fs, fctx, buffer) { Ok(info) => {