vfs_default: move check for fsp->op validity
authorRalph Boehme <slow@samba.org>
Sun, 12 Mar 2017 16:23:09 +0000 (17:23 +0100)
committerJeremy Allison <jra@samba.org>
Tue, 28 Mar 2017 15:45:20 +0000 (17:45 +0200)
Move the check whether fsp->of is valid out of the copy loop in
vfswrap_copy_chunk_send().

It's sufficient to check src_fsp->op and dest_fsp->op once before the
copy loop. fsp->op can only be NULL for internal opens (cf file_new()),
it's not expected to become NULL behind our backs.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/modules/vfs_default.c

index 054ff642c03f25999e992ffa2ed7a4a84ace5e56..545e21a024bd11fe4d12fe66d4c4a4c46f086542 100644 (file)
@@ -1642,6 +1642,16 @@ static struct tevent_req *vfswrap_copy_chunk_send(struct vfs_handle_struct *hand
                return tevent_req_post(req, ev);
        }
 
+       if (src_fsp->op == NULL) {
+               tevent_req_nterror(req, NT_STATUS_INTERNAL_ERROR);
+               return tevent_req_post(req, ev);
+       }
+
+       if (dest_fsp->op == NULL) {
+               tevent_req_nterror(req, NT_STATUS_INTERNAL_ERROR);
+               return tevent_req_post(req, ev);
+       }
+
        /* could use 2.6.33+ sendfile here to do this in kernel */
        while (vfs_cc_state->copied < num) {
                ssize_t ret;
@@ -1651,10 +1661,6 @@ static struct tevent_req *vfswrap_copy_chunk_send(struct vfs_handle_struct *hand
                off_t this_num = MIN(talloc_array_length(vfs_cc_state->buf),
                                     num - vfs_cc_state->copied);
 
-               if (src_fsp->op == NULL) {
-                       tevent_req_nterror(req, NT_STATUS_INTERNAL_ERROR);
-                       return tevent_req_post(req, ev);
-               }
                init_strict_lock_struct(src_fsp,
                                        src_fsp->op->global->open_persistent_id,
                                        src_off,
@@ -1688,11 +1694,6 @@ static struct tevent_req *vfswrap_copy_chunk_send(struct vfs_handle_struct *hand
 
                src_off += ret;
 
-               if (dest_fsp->op == NULL) {
-                       tevent_req_nterror(req, NT_STATUS_INTERNAL_ERROR);
-                       return tevent_req_post(req, ev);
-               }
-
                init_strict_lock_struct(dest_fsp,
                                        dest_fsp->op->global->open_persistent_id,
                                        dest_off,