__u64 offset = hai->hai_extent.offset;
struct stat src_st;
struct stat dst_st;
- char *buf;
+ char *buf = NULL;
__u64 write_total = 0;
__u64 length;
time_t last_print_time = time(NULL);
CT_TRACE("going to copy data from '%s' to '%s'", src, dst);
- buf = malloc(opt.o_chunk_size);
- if (buf == NULL)
- return -ENOMEM;
-
if (fstat(src_fd, &src_st) < 0) {
rc = -errno;
CT_ERROR(rc, "cannot stat '%s'", src);
rc = lseek(src_fd, hai->hai_extent.offset, SEEK_SET);
if (rc < 0) {
- CT_ERROR(errno,
+ 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);
- rc = -errno;
- goto out;
+ return rc;
}
he.offset = offset;
/* Don't read beyond a given extent */
length = min(hai->hai_extent.length, src_st.st_size);
+ buf = malloc(opt.o_chunk_size);
+ if (buf == NULL) {
+ rc = -ENOMEM;
+ goto out;
+ }
+
CT_DEBUG("Going to copy "LPU64" bytes %s -> %s\n", length, src, dst);
while (write_total < length) {
rc = ftruncate(dst_fd, src_st.st_size);
if (rc < 0) {
rc = -errno;
- CT_ERROR(rc,
- "cannot truncate '%s' to size %jd",
+ CT_ERROR(rc, "cannot truncate '%s' to size %jd",
dst, (intmax_t)src_st.st_size);
err_major++;
}
}
- free(buf);
+ if (buf != NULL)
+ free(buf);
return rc;
}
int linkno = 0;
char *ptr;
int depth = 0;
- int sz;
+ ssize_t sz;
sprintf(buf, DFID, PFID(&hai->hai_fid));
sprintf(src, "%s/shadow/", opt.o_hsm_root);
}
/* symlink already exists ? */
sz = readlink(src, buf, sizeof(buf));
+ /* detect truncation */
+ if (sz == sizeof(buf)) {
+ rcf = rcf ? rcf : -E2BIG;
+ CT_ERROR(rcf, "readlink '%s' truncated", src);
+ goto fini_minor;
+ }
if (sz >= 0) {
buf[sz] = '\0';
if (sz == 0 || strncmp(buf, dst, sz) != 0) {