]> wimlib.net Git - wimlib/blobdiff - src/mount_image.c
rebuild_wim(): Fix use of freed memory
[wimlib] / src / mount_image.c
index 55b09890c15d1c86556e8f6305c2a84bfab30209..28a807d7afdfd7d26537a57a97d99e5203564841 100644 (file)
@@ -165,7 +165,8 @@ static int alloc_wimfs_fd(struct wim_inode *inode,
 
        pthread_mutex_lock(&inode->i_mutex);
 
-       DEBUG("Allocating fd for stream ID %u from inode %lx (open = %u, allocated = %u)",
+       DEBUG("Allocating fd for stream ID %u from inode %#"PRIx64" "
+             "(open = %u, allocated = %u)",
              stream_id, inode->i_ino, inode->i_num_opened_fds,
              inode->i_num_allocated_fds);
 
@@ -265,7 +266,7 @@ static int lte_put_fd(struct wim_lookup_table_entry *lte, struct wimfs_fd *fd)
 static int close_wimfs_fd(struct wimfs_fd *fd)
 {
        int ret;
-       DEBUG("Closing fd (inode = %lu, opened = %u, allocated = %u)",
+       DEBUG("Closing fd (ino = %#"PRIx64", opened = %u, allocated = %u)",
              fd->f_inode->i_ino, fd->f_inode->i_num_opened_fds,
              fd->f_inode->i_num_allocated_fds);
        ret = lte_put_fd(fd->f_lte, fd);
@@ -801,7 +802,7 @@ static int rebuild_wim(struct wimfs_context *ctx, int write_flags,
        }
 
        DEBUG("Calculating SHA1 checksums for all new staging files.");
-       list_for_each_entry(lte, &ctx->staging_list, staging_list) {
+       list_for_each_entry_safe(lte, tmp, &ctx->staging_list, staging_list) {
                ret = update_lte_of_staging_file(lte, w->lookup_table);
                if (ret != 0)
                        return ret;
@@ -1612,15 +1613,13 @@ static int wimfs_link(const char *to, const char *from)
        if (!inode)
                return -errno;
 
-       if (inode->i_attributes & FILE_ATTRIBUTE_REPARSE_POINT)
-               return -EEXIST;
-
-       if (inode->i_attributes & FILE_ATTRIBUTE_DIRECTORY)
+       if (inode->i_attributes & (FILE_ATTRIBUTE_DIRECTORY |
+                                  FILE_ATTRIBUTE_REPARSE_POINT))
                return -EPERM;
 
        from_dentry_parent = get_parent_dentry(w, from);
        if (!from_dentry_parent)
-               return -ENOENT;
+               return -errno;
        if (!dentry_is_directory(from_dentry_parent))
                return -ENOTDIR;
 
@@ -1778,7 +1777,7 @@ static int wimfs_open(const char *path, struct fuse_file_info *fi)
        }
 
        ret = alloc_wimfs_fd(inode, stream_id, lte, &fd,
-                             wimfs_ctx_readonly(ctx));
+                            wimfs_ctx_readonly(ctx));
        if (ret != 0)
                return ret;
 
@@ -1835,7 +1834,7 @@ static int wimfs_read(const char *path, char *buf, size_t size,
                wimlib_assert(fd->f_lte->staging_file_name);
                wimlib_assert(fd->staging_fd != -1);
 
-               DEBUG("Seek to offset %zu", offset);
+               DEBUG("Seek to offset %"PRIu64, offset);
 
                if (lseek(fd->staging_fd, offset, SEEK_SET) == -1)
                        return -errno;
@@ -2001,7 +2000,7 @@ static int wimfs_rename(const char *from, const char *to)
                        return -ENOTDIR;
        }
 
-       ret = set_dentry_name(src, to);
+       ret = set_dentry_name(src, path_basename(to));
        if (ret != 0)
                return -ENOMEM;
        if (dst)