]> wimlib.net Git - wimlib/commitdiff
wimlib: strict checks for unassigned flags
authorEric Biggers <ebiggers3@gmail.com>
Fri, 17 Jan 2014 03:05:10 +0000 (21:05 -0600)
committerEric Biggers <ebiggers3@gmail.com>
Fri, 17 Jan 2014 03:11:52 +0000 (21:11 -0600)
This prevents programs that specify unassigned flags from working, since
these flags could be assigned in the future.

15 files changed:
include/wimlib.h
include/wimlib/write.h
programs/imagex.c
src/add_image.c
src/export_image.c
src/extract.c
src/iterate_dir.c
src/lookup_table.c
src/mount_image.c
src/reference.c
src/split.c
src/template.c
src/update_image.c
src/wim.c
src/write.c

index f7286a395b514ce244affb118c9c56e28a8350db..5b164b6d6364577865cfcfdd47e9545e7c77d707 100644 (file)
@@ -1309,7 +1309,8 @@ typedef int (*wimlib_iterate_lookup_table_callback_t)(const struct wimlib_resour
  * scanned.  */
 #define WIMLIB_ADD_FLAG_VERBOSE                        0x00000004
 
-/** Mark the image being added as the bootable image of the WIM. */
+/** Mark the image being added as the bootable image of the WIM.  Not valid for
+ * wimlib_update_image().  */
 #define WIMLIB_ADD_FLAG_BOOT                   0x00000008
 
 /** Store the UNIX owner, group, and mode.  This is done by adding a special
@@ -1770,16 +1771,17 @@ typedef int (*wimlib_iterate_lookup_table_callback_t)(const struct wimlib_resour
 /** @ingroup G_nonstandalone_wims
  * @{ */
 
-/** wimlib_reference_resource_files() only:  Enable shell-style filename
- * globbing.  */
+/** For wimlib_reference_resource_files(), enable shell-style filename globbing.
+ * Ignored by wimlib_reference_resources().  */
 #define WIMLIB_REF_FLAG_GLOB_ENABLE            0x00000001
 
-/** wimlib_reference_resource_files() only:  Issue an error
+/** For wimlib_reference_resource_files(), issue an error
  * (::WIMLIB_ERR_GLOB_HAD_NO_MATCHES) if a glob did not match any files.  The
  * default behavior without this flag is to issue no error at that point, but
  * then attempt to open the glob as a literal path, which of course will fail
  * anyway if no file exists at that path.  No effect if
- * ::WIMLIB_REF_FLAG_GLOB_ENABLE is not also specified.  */
+ * ::WIMLIB_REF_FLAG_GLOB_ENABLE is not also specified.  Ignored by
+ * wimlib_reference_resources().  */
 #define WIMLIB_REF_FLAG_GLOB_ERR_ON_NOMATCH    0x00000002
 
 /** @} */
index 3665eea44fdc71be8004d07604dab26021699ef9..190bf941cf30cd654ca2cbd66a9659c77d389296 100644 (file)
 #define WIMLIB_WRITE_FLAG_USE_EXISTING_TOTALBYTES      0x04000000
 #define WIMLIB_WRITE_FLAG_NO_METADATA                  0x02000000
 #define WIMLIB_WRITE_FLAG_OVERWRITE                    0x01000000
-#define WIMLIB_WRITE_MASK_PUBLIC                       0x00ffffff
+
+/* Keep in sync with wimlib.h  */
+#define WIMLIB_WRITE_MASK_PUBLIC (                       \
+       WIMLIB_WRITE_FLAG_CHECK_INTEGRITY               | \
+       WIMLIB_WRITE_FLAG_NO_CHECK_INTEGRITY            | \
+       WIMLIB_WRITE_FLAG_PIPABLE                       | \
+       WIMLIB_WRITE_FLAG_NOT_PIPABLE                   | \
+       WIMLIB_WRITE_FLAG_RECOMPRESS                    | \
+       WIMLIB_WRITE_FLAG_FSYNC                         | \
+       WIMLIB_WRITE_FLAG_REBUILD                       | \
+       WIMLIB_WRITE_FLAG_SOFT_DELETE                   | \
+       WIMLIB_WRITE_FLAG_IGNORE_READONLY_FLAG          | \
+       WIMLIB_WRITE_FLAG_SKIP_EXTERNAL_WIMS            | \
+       WIMLIB_WRITE_FLAG_STREAMS_OK                    | \
+       WIMLIB_WRITE_FLAG_RESERVED                      | \
+       WIMLIB_WRITE_FLAG_PACK_STREAMS)
 
 #if defined(HAVE_SYS_FILE_H) && defined(HAVE_FLOCK)
 extern int
index 19a78b66522c7dba7bac0f7649b96156a0b1951a..0e3c6e8b0016a8d70dee0e0c012fc9080999701d 100644 (file)
@@ -4071,7 +4071,7 @@ T(
 "                    [--check] [--ref=\"GLOB\"] [--dest-dir=CMD_DIR]\n"
 "                    [--to-stdout] [--no-acls] [--strict-acls]\n"
 "                    [--no-attributes] [--include-invalid-names]\n"
-"                    [--no-wildcards] [--nullglob]\n"
+"                    [--no-wildcards] [--nullglob] [--preserve-dir-structure]\n"
 ),
 [CMD_INFO] =
 T(
index a06ee939cbb9b68c44ad4d3d40ed08231022220c..9b8cffb90f43b49b1708a8f9b02682814bf7add4 100644 (file)
@@ -139,7 +139,7 @@ capture_sources_to_add_cmds(const struct wimlib_capture_source *sources,
                              sources[i].fs_source_path,
                              sources[i].wim_target_path);
                        add_cmds[i].op = WIMLIB_UPDATE_OP_ADD;
-                       add_cmds[i].add.add_flags = add_flags;
+                       add_cmds[i].add.add_flags = add_flags & ~WIMLIB_ADD_FLAG_BOOT;
                        add_cmds[i].add.config = (struct wimlib_capture_config*)config;
                        add_cmds[i].add.fs_source_path = sources[i].fs_source_path;
                        add_cmds[i].add.wim_target_path = sources[i].wim_target_path;
@@ -164,6 +164,10 @@ wimlib_add_image_multisource(WIMStruct *wim,
        DEBUG("Adding image \"%"TS"\" from %zu sources (add_flags=%#x)",
              name, num_sources, add_flags);
 
+       for (size_t i = 0; i < num_sources; i++)
+               if (sources[i].reserved != 0)
+                       return WIMLIB_ERR_INVALID_PARAM;
+
        /* Add the new image (initially empty) */
        ret = wimlib_add_empty_image(wim, name, NULL);
        if (ret)
index 56725e668bb77b113a4bf67fdd6b3c49476e051a..f901ff1973a74038878ff2c3560e8f25efbcfcb6 100644 (file)
@@ -113,6 +113,11 @@ wimlib_export_image(WIMStruct *src_wim,
        u32 orig_dest_image_count;
 
        /* Check for sane parameters.  */
+       if (export_flags & ~(WIMLIB_EXPORT_FLAG_BOOT |
+                            WIMLIB_EXPORT_FLAG_NO_NAMES |
+                            WIMLIB_EXPORT_FLAG_NO_DESCRIPTIONS))
+               return WIMLIB_ERR_INVALID_PARAM;
+
        if (src_wim == NULL || dest_wim == NULL)
                return WIMLIB_ERR_INVALID_PARAM;
 
index 8e695f665e879c6a5adae98535abd82b0320fb0d..995f9cbb1c36b197b844120157f050ce3649292b 100644 (file)
 #define WIMLIB_EXTRACT_FLAG_FROM_PIPE   0x40000000
 #define WIMLIB_EXTRACT_FLAG_FILEMODE    0x20000000
 #define WIMLIB_EXTRACT_FLAG_IMAGEMODE   0x10000000
-#define WIMLIB_EXTRACT_MASK_PUBLIC      0x0fffffff
+
+/* Keep in sync with wimlib.h  */
+#define WIMLIB_EXTRACT_MASK_PUBLIC                             \
+       (WIMLIB_EXTRACT_FLAG_NTFS                       |       \
+        WIMLIB_EXTRACT_FLAG_HARDLINK                   |       \
+        WIMLIB_EXTRACT_FLAG_SYMLINK                    |       \
+        WIMLIB_EXTRACT_FLAG_VERBOSE                    |       \
+        WIMLIB_EXTRACT_FLAG_SEQUENTIAL                 |       \
+        WIMLIB_EXTRACT_FLAG_UNIX_DATA                  |       \
+        WIMLIB_EXTRACT_FLAG_NO_ACLS                    |       \
+        WIMLIB_EXTRACT_FLAG_STRICT_ACLS                |       \
+        WIMLIB_EXTRACT_FLAG_RPFIX                      |       \
+        WIMLIB_EXTRACT_FLAG_NORPFIX                    |       \
+        WIMLIB_EXTRACT_FLAG_TO_STDOUT                  |       \
+        WIMLIB_EXTRACT_FLAG_REPLACE_INVALID_FILENAMES  |       \
+        WIMLIB_EXTRACT_FLAG_ALL_CASE_CONFLICTS         |       \
+        WIMLIB_EXTRACT_FLAG_STRICT_TIMESTAMPS          |       \
+        WIMLIB_EXTRACT_FLAG_STRICT_SHORT_NAMES         |       \
+        WIMLIB_EXTRACT_FLAG_STRICT_SYMLINKS            |       \
+        WIMLIB_EXTRACT_FLAG_RESUME                     |       \
+        WIMLIB_EXTRACT_FLAG_FILE_ORDER                 |       \
+        WIMLIB_EXTRACT_FLAG_GLOB_PATHS                 |       \
+        WIMLIB_EXTRACT_FLAG_STRICT_GLOB                |       \
+        WIMLIB_EXTRACT_FLAG_NO_ATTRIBUTES              |       \
+        WIMLIB_EXTRACT_FLAG_NO_PRESERVE_DIR_STRUCTURE)
 
 /* Given a WIM dentry in the tree to be extracted, resolve all streams in the
  * corresponding inode and set 'out_refcnt' in each to 0.  */
@@ -2881,9 +2905,12 @@ wimlib_extract_files(WIMStruct *wim,
        default_extract_flags |= WIMLIB_EXTRACT_FLAG_NO_PRESERVE_DIR_STRUCTURE;
 
        for (size_t i = 0; i < num_cmds; i++) {
-               int cmd_flags = ((cmds[i].extract_flags |
-                                 default_extract_flags) &
-                                       WIMLIB_EXTRACT_MASK_PUBLIC);
+               int cmd_flags = (cmds[i].extract_flags |
+                                default_extract_flags);
+
+               if (cmd_flags & ~WIMLIB_EXTRACT_MASK_PUBLIC)
+                       return WIMLIB_ERR_INVALID_PARAM;
+
                int cmd_link_flags = (cmd_flags & (WIMLIB_EXTRACT_FLAG_SYMLINK |
                                                   WIMLIB_EXTRACT_FLAG_HARDLINK));
                if (i == 0) {
@@ -2904,9 +2931,8 @@ wimlib_extract_files(WIMStruct *wim,
        }
 
        for (size_t i = 0; i < num_cmds; i++) {
-               int extract_flags = ((cmds[i].extract_flags |
-                                     default_extract_flags) &
-                                       WIMLIB_EXTRACT_MASK_PUBLIC);
+               int extract_flags = (cmds[i].extract_flags |
+                                    default_extract_flags);
                const tchar *target = cmds[i].fs_dest_path;
                const tchar *wim_source_path = cmds[i].wim_source_path;
 
@@ -2933,7 +2959,8 @@ wimlib_extract_paths(WIMStruct *wim,
 {
        int ret;
 
-       extract_flags &= WIMLIB_EXTRACT_MASK_PUBLIC;
+       if (extract_flags & ~WIMLIB_EXTRACT_MASK_PUBLIC)
+               return WIMLIB_ERR_INVALID_PARAM;
 
        ret = do_wimlib_extract_paths(wim, image, target, paths, num_paths,
                                      extract_flags, progress_func);
@@ -2979,7 +3006,8 @@ wimlib_extract_image_from_pipe(int pipe_fd, const tchar *image_num_or_name,
        int image;
        unsigned i;
 
-       extract_flags &= WIMLIB_EXTRACT_MASK_PUBLIC;
+       if (extract_flags & ~WIMLIB_EXTRACT_MASK_PUBLIC)
+               return WIMLIB_ERR_INVALID_PARAM;
 
        if (extract_flags & WIMLIB_EXTRACT_FLAG_FILE_ORDER)
                return WIMLIB_ERR_INVALID_PARAM;
@@ -3136,7 +3164,8 @@ wimlib_extract_image(WIMStruct *wim,
                     int extract_flags,
                     wimlib_progress_func_t progress_func)
 {
-       extract_flags &= WIMLIB_EXTRACT_MASK_PUBLIC;
+       if (extract_flags & ~WIMLIB_EXTRACT_MASK_PUBLIC)
+               return WIMLIB_ERR_INVALID_PARAM;
        return do_wimlib_extract_image(wim, image, target, extract_flags,
                                       progress_func);
 }
index 042c76ac07d030f78d40a4b8c40d18ae13071533..cc5c63b89c4b52626c5bea06d24304cf89194b70 100644 (file)
@@ -242,6 +242,11 @@ wimlib_iterate_dir_tree(WIMStruct *wim, int image, const tchar *_path,
        tchar *path;
        int ret;
 
+       if (flags & ~(WIMLIB_ITERATE_DIR_TREE_FLAG_RECURSIVE |
+                     WIMLIB_ITERATE_DIR_TREE_FLAG_CHILDREN |
+                     WIMLIB_ITERATE_DIR_TREE_FLAG_RESOURCES_NEEDED))
+               return WIMLIB_ERR_INVALID_PARAM;
+
        path = canonicalize_wim_path(_path);
        if (path == NULL)
                return WIMLIB_ERR_NOMEM;
index c76823d14e4cacc3b4be3f620a14cadcb9dd13ec..4a3bc1e23b4f3f0f4173f9fa0a4ed28a0d3f2a02 100644 (file)
@@ -1181,6 +1181,9 @@ wimlib_iterate_lookup_table(WIMStruct *wim, int flags,
                            wimlib_iterate_lookup_table_callback_t cb,
                            void *user_ctx)
 {
+       if (flags != 0)
+               return WIMLIB_ERR_INVALID_PARAM;
+
        struct iterate_lte_context ctx = {
                .cb = cb,
                .user_ctx = user_ctx,
index 7c480ebc76c02c7af9808b87f151c5188a8506ae..7b3a91470d7c7c5c6b57df3412a4f49bf6dd9b52 100644 (file)
@@ -2410,6 +2410,15 @@ wimlib_mount_image(WIMStruct *wim, int image, const char *dir,
        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)
@@ -2570,6 +2579,13 @@ wimlib_unmount_image(const char *dir, int unmount_flags,
        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);
index 1a83a4a6cbcf315b85051e591c758fac90a10e0f..3238abe464434be1cd5be79e0cfb854ff6122984 100644 (file)
@@ -33,6 +33,9 @@
 #include "wimlib/lookup_table.h"
 #include "wimlib/wim.h"
 
+#define WIMLIB_REF_MASK_PUBLIC (WIMLIB_REF_FLAG_GLOB_ENABLE | \
+                               WIMLIB_REF_FLAG_GLOB_ERR_ON_NOMATCH)
+
 static int
 lte_clone_if_new(struct wim_lookup_table_entry *lte, void *_lookup_table)
 {
@@ -76,6 +79,9 @@ wimlib_reference_resources(WIMStruct *wim,
        if (num_resource_wims != 0 && resource_wims == NULL)
                return WIMLIB_ERR_INVALID_PARAM;
 
+       if (ref_flags & ~WIMLIB_REF_MASK_PUBLIC)
+               return WIMLIB_ERR_INVALID_PARAM;
+
        for (i = 0; i < num_resource_wims; i++)
                if (resource_wims[i] == NULL)
                        return WIMLIB_ERR_INVALID_PARAM;
@@ -195,6 +201,9 @@ wimlib_reference_resource_files(WIMStruct *wim,
        unsigned i;
        int ret;
 
+       if (ref_flags & ~WIMLIB_REF_MASK_PUBLIC)
+               return WIMLIB_ERR_INVALID_PARAM;
+
        if (ref_flags & WIMLIB_REF_FLAG_GLOB_ENABLE) {
                for (i = 0; i < count; i++) {
                        ret = reference_resource_glob(wim,
index 2688e7f63c2a3496e9e1cbfbdfc6990ad849bc2e..d1317cf9d44f0ce82b810e65b1f53f28852d43c7 100644 (file)
@@ -115,7 +115,7 @@ write_split_wim(WIMStruct *orig_wim, const tchar *swm_name,
                                      &progress);
                }
 
-               part_write_flags = write_flags & WIMLIB_WRITE_MASK_PUBLIC;
+               part_write_flags = write_flags;
                part_write_flags |= WIMLIB_WRITE_FLAG_USE_EXISTING_TOTALBYTES;
                if (part_number != 1)
                        part_write_flags |= WIMLIB_WRITE_FLAG_NO_METADATA;
@@ -211,6 +211,9 @@ wimlib_split(WIMStruct *wim, const tchar *swm_name,
        if (swm_name == NULL || swm_name[0] == T('\0') || part_size == 0)
                return WIMLIB_ERR_INVALID_PARAM;
 
+       if (write_flags & ~WIMLIB_WRITE_MASK_PUBLIC)
+               return WIMLIB_ERR_INVALID_PARAM;
+
        if (!wim_has_metadata(wim))
                return WIMLIB_ERR_METADATA_NOT_FOUND;
 
index 7348258ee81539665fe7f2045a557478fa9c2fb1..6b21015a0aedf6e7b5000cc962213870f74d74ee 100644 (file)
@@ -212,6 +212,9 @@ wimlib_reference_template_image(WIMStruct *wim, int new_image,
        int ret;
        struct wim_image_metadata *new_imd;
 
+       if (flags != 0)
+               return WIMLIB_ERR_INVALID_PARAM;
+
        if (wim == NULL || template_wim == NULL)
                return WIMLIB_ERR_INVALID_PARAM;
 
index b7a3abdff9c14ec64d6ac9d4ad0d142e6d396e16..5a5ae69066f590f119fed933296a410c545be2bc 100644 (file)
@@ -465,6 +465,21 @@ check_add_command(struct wimlib_update_command *cmd,
 {
        int add_flags = cmd->add.add_flags;
 
+       if (add_flags & ~(WIMLIB_ADD_FLAG_NTFS |
+                         WIMLIB_ADD_FLAG_DEREFERENCE |
+                         WIMLIB_ADD_FLAG_VERBOSE |
+                         /* BOOT doesn't make sense for wimlib_update_image()  */
+                         /*WIMLIB_ADD_FLAG_BOOT |*/
+                         WIMLIB_ADD_FLAG_UNIX_DATA |
+                         WIMLIB_ADD_FLAG_NO_ACLS |
+                         WIMLIB_ADD_FLAG_STRICT_ACLS |
+                         WIMLIB_ADD_FLAG_EXCLUDE_VERBOSE |
+                         WIMLIB_ADD_FLAG_RPFIX |
+                         WIMLIB_ADD_FLAG_NORPFIX |
+                         WIMLIB_ADD_FLAG_NO_UNSUPPORTED_EXCLUDE |
+                         WIMLIB_ADD_FLAG_WINCONFIG))
+               return WIMLIB_ERR_INVALID_PARAM;
+
        /* Are we adding the entire image or not?  An empty wim_target_path
         * indicates that the tree we're adding is to be placed in the root of
         * the image.  We consider this to be capturing the entire image,
@@ -534,6 +549,23 @@ check_add_command(struct wimlib_update_command *cmd,
        return 0;
 }
 
+static int
+check_delete_command(const struct wimlib_update_command *cmd)
+{
+       if (cmd->delete_.delete_flags & ~(WIMLIB_DELETE_FLAG_FORCE |
+                                         WIMLIB_DELETE_FLAG_RECURSIVE))
+               return WIMLIB_ERR_INVALID_PARAM;
+       return 0;
+}
+
+static int
+check_rename_command(const struct wimlib_update_command *cmd)
+{
+       if (cmd->rename.rename_flags != 0)
+               return WIMLIB_ERR_INVALID_PARAM;
+       return 0;
+}
+
 static int
 check_update_command(struct wimlib_update_command *cmd,
                     const struct wim_header *hdr)
@@ -542,8 +574,9 @@ check_update_command(struct wimlib_update_command *cmd,
        case WIMLIB_UPDATE_OP_ADD:
                return check_add_command(cmd, hdr);
        case WIMLIB_UPDATE_OP_DELETE:
+               return check_delete_command(cmd);
        case WIMLIB_UPDATE_OP_RENAME:
-               break;
+               return check_rename_command(cmd);
        }
        return 0;
 }
@@ -667,6 +700,9 @@ wimlib_update_image(WIMStruct *wim,
        struct wimlib_update_command *cmds_copy;
        bool deletion_requested = false;
 
+       if (update_flags & ~WIMLIB_UPDATE_FLAG_SEND_PROGRESS)
+               return WIMLIB_ERR_INVALID_PARAM;
+
        DEBUG("Updating image %d with %zu commands", image, num_cmds);
 
        for (size_t i = 0; i < num_cmds; i++)
index d885b7970988f6d6412cf1686b4f32c3d5c9c155..febc68aac69bfd122dc55084ab173c1ebfc201e8 100644 (file)
--- a/src/wim.c
+++ b/src/wim.c
@@ -392,6 +392,12 @@ wimlib_set_wim_info(WIMStruct *wim, const struct wimlib_wim_info *info, int whic
 {
        int ret;
 
+       if (which & ~(WIMLIB_CHANGE_READONLY_FLAG |
+                     WIMLIB_CHANGE_GUID |
+                     WIMLIB_CHANGE_BOOT_INDEX |
+                     WIMLIB_CHANGE_RPFIX_FLAG))
+               return WIMLIB_ERR_INVALID_PARAM;
+
        if (which & WIMLIB_CHANGE_READONLY_FLAG) {
                if (info->is_marked_readonly)
                        wim->hdr.flags |= WIM_HDR_FLAG_READONLY;
@@ -721,7 +727,11 @@ WIMLIBAPI int
 wimlib_open_wim(const tchar *wimfile, int open_flags,
                WIMStruct **wim_ret, wimlib_progress_func_t progress_func)
 {
-       open_flags &= WIMLIB_OPEN_MASK_PUBLIC;
+       if (open_flags & ~(WIMLIB_OPEN_FLAG_CHECK_INTEGRITY |
+                          WIMLIB_OPEN_FLAG_ERROR_IF_SPLIT |
+                          WIMLIB_OPEN_FLAG_WRITE_ACCESS))
+               return WIMLIB_ERR_INVALID_PARAM;
+
        return open_wim_as_WIMStruct(wimfile, open_flags, wim_ret,
                                     progress_func);
 }
@@ -975,6 +985,15 @@ wimlib_global_init(int init_flags)
 
        if (already_inited)
                return 0;
+
+       if (init_flags & ~(WIMLIB_INIT_FLAG_ASSUME_UTF8 |
+                          WIMLIB_INIT_FLAG_DONT_ACQUIRE_PRIVILEGES |
+                          WIMLIB_INIT_FLAG_STRICT_CAPTURE_PRIVILEGES |
+                          WIMLIB_INIT_FLAG_STRICT_APPLY_PRIVILEGES |
+                          WIMLIB_INIT_FLAG_DEFAULT_CASE_SENSITIVE |
+                          WIMLIB_INIT_FLAG_DEFAULT_CASE_INSENSITIVE))
+               return WIMLIB_ERR_INVALID_PARAM;
+
        libxml_global_init();
        if (!(init_flags & WIMLIB_INIT_FLAG_ASSUME_UTF8)) {
                wimlib_mbs_is_utf8 = test_locale_ctype_utf8();
index 1df05c95402c7570802c6b2c6a3a83abe7b2aeee..07b557500b894ae70c770705b10d12500cdae5c2 100644 (file)
@@ -2819,10 +2819,11 @@ wimlib_write(WIMStruct *wim, const tchar *path,
             int image, int write_flags, unsigned num_threads,
             wimlib_progress_func_t progress_func)
 {
-       if (!path)
+       if (write_flags & ~WIMLIB_WRITE_MASK_PUBLIC)
                return WIMLIB_ERR_INVALID_PARAM;
 
-       write_flags &= WIMLIB_WRITE_MASK_PUBLIC;
+       if (path == NULL || path[0] == T('\0'))
+               return WIMLIB_ERR_INVALID_PARAM;
 
        return write_standalone_wim(wim, path, image, write_flags,
                                    num_threads, progress_func);
@@ -2834,10 +2835,12 @@ wimlib_write_to_fd(WIMStruct *wim, int fd,
                   int image, int write_flags, unsigned num_threads,
                   wimlib_progress_func_t progress_func)
 {
+       if (write_flags & ~WIMLIB_WRITE_MASK_PUBLIC)
+               return WIMLIB_ERR_INVALID_PARAM;
+
        if (fd < 0)
                return WIMLIB_ERR_INVALID_PARAM;
 
-       write_flags &= WIMLIB_WRITE_MASK_PUBLIC;
        write_flags |= WIMLIB_WRITE_FLAG_FILE_DESCRIPTOR;
 
        return write_standalone_wim(wim, &fd, image, write_flags,
@@ -3200,9 +3203,7 @@ wimlib_overwrite(WIMStruct *wim, int write_flags,
        int ret;
        u32 orig_hdr_flags;
 
-       write_flags &= WIMLIB_WRITE_MASK_PUBLIC;
-
-       if (write_flags & WIMLIB_WRITE_FLAG_FILE_DESCRIPTOR)
+       if (write_flags & ~WIMLIB_WRITE_MASK_PUBLIC)
                return WIMLIB_ERR_INVALID_PARAM;
 
        if (!wim->filename)