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>
#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
********************************************************************/
struct iovec;
+bool sys_valid_io_range(off_t offset, size_t length);
ssize_t sys_read(int fd, void *buf, size_t count);
void sys_read_v(int fd, void *buf, size_t count);
ssize_t sys_write(int fd, const void *buf, size_t count);