]> wimlib.net Git - wimlib/blobdiff - src/win32_apply.c
Avoid passing NULL as memcpy source (undefined behavior)
[wimlib] / src / win32_apply.c
index c35fbec26b7b769099b94ce930d1eef8013d45f5..cb488a9f6ed656013b74b67cacbf74b6c63914af 100644 (file)
@@ -686,8 +686,8 @@ start_wimboot_extraction(struct list_head *dentry_list, struct win32_apply_ctx *
        int ret;
        struct wim_dentry *dentry;
 
-       if (!wim_info_get_wimboot(ctx->common.wim->wim_info,
-                                 ctx->common.wim->current_image))
+       if (!xml_get_wimboot(ctx->common.wim->xml_info,
+                            ctx->common.wim->current_image))
                WARNING("The WIM image is not marked as WIMBoot compatible.  This usually\n"
                        "          means it is not intended to be used to back a Windows operating\n"
                        "          system.  Proceeding anyway.");
@@ -901,7 +901,9 @@ build_extraction_path(const struct wim_dentry *dentry,
             d = d->d_parent)
        {
                p -= d->d_extraction_name_nchars;
-               wmemcpy(p, d->d_extraction_name, d->d_extraction_name_nchars);
+               if (d->d_extraction_name_nchars)
+                       wmemcpy(p, d->d_extraction_name,
+                               d->d_extraction_name_nchars);
                *--p = '\\';
        }
        /* No leading slash  */
@@ -989,6 +991,9 @@ open_target_directory(struct win32_apply_ctx *ctx)
        ctx->attr.Length = sizeof(ctx->attr);
        ctx->attr.RootDirectory = NULL;
        ctx->attr.ObjectName = &ctx->target_ntpath;
+
+       /* Don't use FILE_OPEN_REPARSE_POINT here; we want the extraction to
+        * happen at the directory "pointed to" by the reparse point. */
        status = (*func_NtCreateFile)(&ctx->h_target,
                                      FILE_TRAVERSE,
                                      &ctx->attr,
@@ -998,7 +1003,6 @@ open_target_directory(struct win32_apply_ctx *ctx)
                                      FILE_SHARE_VALID_FLAGS,
                                      FILE_OPEN_IF,
                                      FILE_DIRECTORY_FILE |
-                                             FILE_OPEN_REPARSE_POINT |
                                              FILE_OPEN_FOR_BACKUP_INTENT,
                                      NULL,
                                      0);
@@ -1097,6 +1101,7 @@ adjust_compression_attribute(HANDLE h, const struct wim_dentry *dentry,
        FILE_BASIC_INFORMATION info;
        NTSTATUS status;
        USHORT compression_state;
+       DWORD bytes_returned;
 
        /* Get current attributes  */
        status = (*func_NtQueryInformationFile)(h, &ctx->iosb,
@@ -1116,20 +1121,14 @@ adjust_compression_attribute(HANDLE h, const struct wim_dentry *dentry,
        else
                compression_state = COMPRESSION_FORMAT_NONE;
 
-       status = (*func_NtFsControlFile)(h,
-                                        NULL,
-                                        NULL,
-                                        NULL,
-                                        &ctx->iosb,
-                                        FSCTL_SET_COMPRESSION,
-                                        &compression_state,
-                                        sizeof(USHORT),
-                                        NULL,
-                                        0);
-       if (NT_SUCCESS(status))
+       /* Note: don't use NtFsControlFile() here unless prepared to handle
+        * STATUS_PENDING.  */
+       if (DeviceIoControl(h, FSCTL_SET_COMPRESSION,
+                           &compression_state, sizeof(USHORT), NULL, 0,
+                           &bytes_returned, NULL))
                return 0;
 
-       winnt_error(status, L"Can't %s compression attribute on \"%ls\"",
+       win32_error(GetLastError(), L"Can't %s compression attribute on \"%ls\"",
                    (compressed ? "set" : "clear"), current_path(ctx));
        return WIMLIB_ERR_SET_ATTRIBUTES;
 }
@@ -2938,8 +2937,8 @@ win32_extract(struct list_head *dentry_list, struct apply_ctx *_ctx)
                        goto out;
        }
 
-       ctx->windows_build_number = wim_info_get_windows_build_number(ctx->common.wim->wim_info,
-                                                                     ctx->common.wim->current_image);
+       ctx->windows_build_number = xml_get_windows_build_number(ctx->common.wim->xml_info,
+                                                                ctx->common.wim->current_image);
 
        dentry_count = count_dentries(dentry_list);