From: xie xingguo Date: Fri, 19 Feb 2016 09:56:28 +0000 (+0800) Subject: os/filestore: fix result code overwritten for clone X-Git-Tag: v10.1.0~250^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=877eae85ce7630fa05cc16f5f71be40e08607a5c;p=ceph.git os/filestore: fix result code overwritten for clone 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 --- diff --git a/src/os/filestore/FileStore.cc b/src/os/filestore/FileStore.cc index 548b1d926f75..a35c78149777 100644 --- a/src/os/filestore/FileStore.cc +++ b/src/os/filestore/FileStore.cc @@ -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)