]> wimlib.net Git - wimlib/blobdiff - src/mount_image.c
wimlib_mount_image(): Correctly return NOMEM in one case
[wimlib] / src / mount_image.c
index 7c480ebc76c02c7af9808b87f151c5188a8506ae..41478d92a43dd8566c83c53a3f15bc35ff48c01a 100644 (file)
@@ -164,7 +164,8 @@ get_lookup_flags(const struct wimfs_context *ctx)
 static inline int
 flags_writable(int open_flags)
 {
 static inline int
 flags_writable(int open_flags)
 {
-       return open_flags & (O_RDWR | O_WRONLY);
+       int accmode = (open_flags & O_ACCMODE);
+       return (accmode == O_RDWR || accmode == O_WRONLY);
 }
 
 /*
 }
 
 /*
@@ -667,6 +668,7 @@ extract_resource_to_staging_dir(struct wim_inode *inode,
                }
        }
 
                }
        }
 
+       lte_put_resource(new_lte);
        new_lte->refcnt              = inode->i_nlink;
        new_lte->resource_location   = RESOURCE_IN_STAGING_FILE;
        new_lte->staging_file_name   = staging_file_name;
        new_lte->refcnt              = inode->i_nlink;
        new_lte->resource_location   = RESOURCE_IN_STAGING_FILE;
        new_lte->staging_file_name   = staging_file_name;
@@ -2410,6 +2412,15 @@ wimlib_mount_image(WIMStruct *wim, int image, const char *dir,
        if (!wim || !dir)
                return WIMLIB_ERR_INVALID_PARAM;
 
        if (!wim || !dir)
                return WIMLIB_ERR_INVALID_PARAM;
 
+       if (mount_flags & ~(WIMLIB_MOUNT_FLAG_READWRITE |
+                           WIMLIB_MOUNT_FLAG_DEBUG |
+                           WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_NONE |
+                           WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_XATTR |
+                           WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_WINDOWS |
+                           WIMLIB_MOUNT_FLAG_UNIX_DATA |
+                           WIMLIB_MOUNT_FLAG_ALLOW_OTHER))
+               return WIMLIB_ERR_INVALID_PARAM;
+
        if (mount_flags & WIMLIB_MOUNT_FLAG_READWRITE) {
                ret = can_delete_from_wim(wim);
                if (ret)
        if (mount_flags & WIMLIB_MOUNT_FLAG_READWRITE) {
                ret = can_delete_from_wim(wim);
                if (ret)
@@ -2465,8 +2476,10 @@ wimlib_mount_image(WIMStruct *wim, int image, const char *dir,
        DEBUG("Preparing arguments to fuse_main()");
 
        dir_copy = STRDUP(dir);
        DEBUG("Preparing arguments to fuse_main()");
 
        dir_copy = STRDUP(dir);
-       if (!dir_copy)
+       if (!dir_copy) {
+               ret = WIMLIB_ERR_NOMEM;
                goto out_free_message_queue_names;
                goto out_free_message_queue_names;
+       }
 
        argc = 0;
        argv[argc++] = "wimlib";
 
        argc = 0;
        argv[argc++] = "wimlib";
@@ -2570,6 +2583,13 @@ wimlib_unmount_image(const char *dir, int unmount_flags,
        int ret;
        struct wimfs_context wimfs_ctx;
 
        int ret;
        struct wimfs_context wimfs_ctx;
 
+       if (unmount_flags & ~(WIMLIB_UNMOUNT_FLAG_CHECK_INTEGRITY |
+                             WIMLIB_UNMOUNT_FLAG_COMMIT |
+                             WIMLIB_UNMOUNT_FLAG_REBUILD |
+                             WIMLIB_UNMOUNT_FLAG_RECOMPRESS |
+                             WIMLIB_UNMOUNT_FLAG_LAZY))
+               return WIMLIB_ERR_INVALID_PARAM;
+
        init_wimfs_context(&wimfs_ctx);
 
        ret = set_message_queue_names(&wimfs_ctx, dir);
        init_wimfs_context(&wimfs_ctx);
 
        ret = set_message_queue_names(&wimfs_ctx, dir);