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>
}
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)