From 62cc18dcac29b803d191af7d7800067a23a33458 Mon Sep 17 00:00:00 2001 From: Ralph Boehme Date: Fri, 29 Nov 2024 13:00:30 +0100 Subject: [PATCH] smbd: add vfs_valid_allocation_range() as a copy of vfs_valid_pwrite_range() Not a copy of the whole code obviously, a copy of behaviour. A subsequent commit will further change vfs_valid_pwrite_range(). Existing callers of vfs_valid_pwrite_range() that are not calling it in the write-IO codepath, but when dealing with allocation and size, are converted to use vfs_valid_allocation_range(). No change in behaviour. Signed-off-by: Ralph Boehme Reviewed-by: Jeremy Allison --- source3/modules/vfs_default.c | 2 +- source3/smbd/proto.h | 1 + source3/smbd/vfs.c | 15 ++++++++++----- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/source3/modules/vfs_default.c b/source3/modules/vfs_default.c index f4032656e1f..a48a4de40a6 100644 --- a/source3/modules/vfs_default.c +++ b/source3/modules/vfs_default.c @@ -2894,7 +2894,7 @@ static int strict_allocate_ftruncate(vfs_handle_struct *handle, files_struct *fs SMB_STRUCT_STAT *pst; bool ok; - ok = vfs_valid_pwrite_range(len, 0); + ok = vfs_valid_allocation_range(len, 0); if (!ok) { errno = EINVAL; return -1; diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h index e7de9df4683..e61b137ea13 100644 --- a/source3/smbd/proto.h +++ b/source3/smbd/proto.h @@ -1166,6 +1166,7 @@ bool smbd_vfs_init(connection_struct *conn); NTSTATUS vfs_file_exist(connection_struct *conn, struct smb_filename *smb_fname); bool vfs_valid_pread_range(off_t offset, size_t length); bool vfs_valid_pwrite_range(off_t offset, size_t length); +bool vfs_valid_allocation_range(off_t offset, size_t length); ssize_t vfs_pwrite_data(struct smb_request *req, files_struct *fsp, const char *buffer, diff --git a/source3/smbd/vfs.c b/source3/smbd/vfs.c index 462f57f854e..512fa361a15 100644 --- a/source3/smbd/vfs.c +++ b/source3/smbd/vfs.c @@ -423,7 +423,7 @@ bool vfs_valid_pread_range(off_t offset, size_t length) return sys_valid_io_range(offset, length); } -bool vfs_valid_pwrite_range(off_t offset, size_t length) +bool vfs_valid_allocation_range(off_t offset, size_t length) { /* * See MAXFILESIZE in [MS-FSA] 2.1.5.3 Server Requests a Write @@ -449,6 +449,11 @@ bool vfs_valid_pwrite_range(off_t offset, size_t length) return true; } +bool vfs_valid_pwrite_range(off_t offset, size_t length) +{ + return vfs_valid_allocation_range(offset, length); +} + ssize_t vfs_pwrite_data(struct smb_request *req, files_struct *fsp, const char *buffer, @@ -549,7 +554,7 @@ int vfs_allocate_file_space(files_struct *fsp, uint64_t len) DEBUG(10,("vfs_allocate_file_space: file %s, len %.0f\n", fsp_str_dbg(fsp), (double)len)); - ok = vfs_valid_pwrite_range((off_t)len, 0); + ok = vfs_valid_allocation_range((off_t)len, 0); if (!ok) { DEBUG(0,("vfs_allocate_file_space: %s negative/invalid len " "requested.\n", fsp_str_dbg(fsp))); @@ -638,7 +643,7 @@ int vfs_set_filelen(files_struct *fsp, off_t len) int ret; bool ok; - ok = vfs_valid_pwrite_range(len, 0); + ok = vfs_valid_allocation_range(len, 0); if (!ok) { errno = EINVAL; return -1; @@ -679,7 +684,7 @@ int vfs_slow_fallocate(files_struct *fsp, off_t offset, off_t len) size_t total = 0; bool ok; - ok = vfs_valid_pwrite_range(offset, len); + ok = vfs_valid_allocation_range(offset, len); if (!ok) { errno = EINVAL; return -1; @@ -726,7 +731,7 @@ int vfs_fill_sparse(files_struct *fsp, off_t len) size_t num_to_write; bool ok; - ok = vfs_valid_pwrite_range(len, 0); + ok = vfs_valid_allocation_range(len, 0); if (!ok) { errno = EINVAL; return -1; -- 2.47.3