Strengthen copytool file bounds checking in either full
or partial/extent mode.
Signed-off-by: Bruno Faccini <bruno.faccini@intel.com>
Change-Id: I36939f9a18362ca3131e39b8d390978dfc79405a
Reviewed-on: http://review.whamcloud.com/13226
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Henri Doreau <henri.doreau@cea.fr>
Reviewed-by: Hongchao Zhang <hongchao.zhang@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
+ if (hai->hai_extent.offset > (__u64)src_st.st_size) {
+ rc = -EINVAL;
+ CT_ERROR(rc, "Trying to start reading past end ("LPU64" > "
+ "%jd) of '%s' source file", hai->hai_extent.offset,
+ (intmax_t)src_st.st_size, src);
+ return rc;
+ }
+
if (fstat(dst_fd, &dst_st) < 0) {
rc = -errno;
CT_ERROR(rc, "cannot stat '%s'", dst);
if (fstat(dst_fd, &dst_st) < 0) {
rc = -errno;
CT_ERROR(rc, "cannot stat '%s'", dst);
- rc = lseek(src_fd, hai->hai_extent.offset, SEEK_SET);
- if (rc < 0) {
- rc = -errno;
- CT_ERROR(rc,
- "cannot seek for read to "LPU64" (len %jd) in '%s'",
- hai->hai_extent.offset, (intmax_t)src_st.st_size, src);
- return rc;
- }
-
/* Don't read beyond a given extent */
/* Don't read beyond a given extent */
- length = min(hai->hai_extent.length, src_st.st_size);
+ length = min(hai->hai_extent.length,
+ src_st.st_size - hai->hai_extent.offset);
start_time = last_bw_print = last_report_time = time(NULL);
start_time = last_bw_print = last_report_time = time(NULL);