From 751ce5021b4ad47258db1c8dc7c90ee9155a9211 Mon Sep 17 00:00:00 2001 From: "Niall Douglas (s [underscore] sourceforge {at} nedprod [dot] com)" Date: Thu, 16 Jul 2020 21:49:57 +0100 Subject: Trap passing a non-writable handle into file_handle::clone_extents_to(). --- include/llfio/v2.0/detail/impl/posix/file_handle.ipp | 4 ++++ include/llfio/v2.0/detail/impl/windows/file_handle.ipp | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/include/llfio/v2.0/detail/impl/posix/file_handle.ipp b/include/llfio/v2.0/detail/impl/posix/file_handle.ipp index bdc57f25..59175770 100644 --- a/include/llfio/v2.0/detail/impl/posix/file_handle.ipp +++ b/include/llfio/v2.0/detail/impl/posix/file_handle.ipp @@ -434,6 +434,10 @@ result file_handle::clone_extents_to(file_handle::exte try { LLFIO_LOG_FUNCTION_CALL(this); + if(!dest_.is_writable()) + { + return errc::bad_file_descriptor; + } OUTCOME_TRY(auto mycurrentlength, maximum_extent()); if(extent.offset == (extent_type) -1 && extent.length == (extent_type) -1) { diff --git a/include/llfio/v2.0/detail/impl/windows/file_handle.ipp b/include/llfio/v2.0/detail/impl/windows/file_handle.ipp index 55154f4b..b9137ce8 100644 --- a/include/llfio/v2.0/detail/impl/windows/file_handle.ipp +++ b/include/llfio/v2.0/detail/impl/windows/file_handle.ipp @@ -410,6 +410,10 @@ result file_handle::clone_extents_to(file_handle::exte windows_nt_kernel::init(); using namespace windows_nt_kernel; LLFIO_LOG_FUNCTION_CALL(this); + if(!dest_.is_writable()) + { + return errc::bad_file_descriptor; + } OUTCOME_TRY(auto mycurrentlength, maximum_extent()); if(extent.offset == (extent_type) -1 && extent.length == (extent_type) -1) { -- cgit v1.2.3