diff options
author | Stefan Metzmacher <metze@samba.org> | 2020-05-08 13:06:54 +0200 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2020-05-12 19:53:43 +0000 |
commit | e02cbd5c3ea6903d2b7b43c3193b8662d029ecdd (patch) | |
tree | 6d162a5884ea2c3390fc096a477c108138d0f925 /lib/util/sys_rw.c | |
parent | 54de0e4a3e46a53db5262963e64b109c567554a1 (diff) | |
download | samba-e02cbd5c3ea6903d2b7b43c3193b8662d029ecdd.tar.gz |
lib: util: Add sys_valid_io_range()
This implements the contraints of
[MS-FSA] 2.1.5.2 Server Requests a Read.
The special handling of [MS-FSA] 2.1.5.3 Server Requests a Write
with offset < 0, should be handled by higher layers!
Which means the check can also be used for writes.
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14361
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'lib/util/sys_rw.c')
-rw-r--r-- | lib/util/sys_rw.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/util/sys_rw.c b/lib/util/sys_rw.c index 9a6cdcaa606..6fa7ca57365 100644 --- a/lib/util/sys_rw.c +++ b/lib/util/sys_rw.c @@ -24,6 +24,30 @@ #include "system/filesys.h" #include "lib/util/sys_rw.h" +bool sys_valid_io_range(off_t offset, size_t length) +{ + uint64_t last_byte_ofs; + + if (offset < 0) { + return false; + } + + if (offset > INT64_MAX) { + return false; + } + + if (length > UINT32_MAX) { + return false; + } + + last_byte_ofs = (uint64_t)offset + (uint64_t)length; + if (last_byte_ofs > INT64_MAX) { + return false; + } + + return true; +} + /******************************************************************* A read wrapper that will deal with EINTR/EWOULDBLOCK ********************************************************************/ |