]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
os/filestore: fix result code overwritten for clone
authorxie xingguo <xie.xingguo@zte.com.cn>
Fri, 19 Feb 2016 09:56:28 +0000 (17:56 +0800)
committerxie xingguo <xie.xingguo@zte.com.cn>
Fri, 19 Feb 2016 10:10:22 +0000 (18:10 +0800)
During the clone process, the result code of syscall-fstat which is intend for
getting the source size for copying is not checked and will be overwritten
by the following call, which is of potential risk and thus should be considered
as unsafe.

This pr solves the above problem by adding result checking against failure.
Also result code is reset to errno for better tracing if the ftruncate syscall
failed.

Fixes: #14817
Signed-off-by: xie xingguo <xie.xingguo@zte.com.cn>
src/os/filestore/FileStore.cc

index 548b1d926f75b2285bd5708c9e0ce9e45d7fe23c..a35c781497779b433ec9793d9da2107f3e058c2a 100644 (file)
@@ -3296,16 +3296,21 @@ int FileStore::_clone(const coll_t& cid, const ghobject_t& oldoid, const ghobjec
     }
     r = ::ftruncate(**n, 0);
     if (r < 0) {
+      r = -errno;
       goto out3;
     }
     struct stat st;
-    ::fstat(**o, &st);
-    r = _do_clone_range(**o, **n, 0, st.st_size, 0);
+    r = ::fstat(**o, &st);
     if (r < 0) {
       r = -errno;
       goto out3;
     }
 
+    r = _do_clone_range(**o, **n, 0, st.st_size, 0);
+    if (r < 0) {
+      goto out3;
+    }
+
     dout(20) << "objectmap clone" << dendl;
     r = object_map->clone(oldoid, newoid, &spos);
     if (r < 0 && r != -ENOENT)