]> wimlib.net Git - wimlib/blobdiff - src/win32_apply.c
Win32: Fix reparse point fixup bugs
[wimlib] / src / win32_apply.c
index cc466b19826f8630f9368f9ff71d16c175ae2087..010b9bee6171fdbd3027b2b9907ff22304a5cfaf 100644 (file)
 
 #ifdef __WIN32__
 
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
 #include <aclapi.h> /* for SetSecurityInfo() */
 
-#include "win32_common.h"
-#include "wimlib_internal.h"
-#include "dentry.h"
-#include "lookup_table.h"
-#include "endianness.h"
+#include "wimlib/win32_common.h"
+
+#include "wimlib/apply.h"
+#include "wimlib/dentry.h"
+#include "wimlib/endianness.h"
+#include "wimlib/error.h"
+#include "wimlib/lookup_table.h"
+#include "wimlib/metadata.h"
+#include "wimlib/reparse.h"
+#include "wimlib/security.h"
 
 #define MAX_CREATE_HARD_LINK_WARNINGS 5
 #define MAX_CREATE_SOFT_LINK_WARNINGS 5
@@ -48,6 +57,7 @@ L"If you are not running this program as the administrator, you may\n"
 
 static int
 win32_extract_try_rpfix(u8 *rpbuf,
+                       u16 *rpbuflen_p,
                        const wchar_t *extract_root_realpath,
                        unsigned extract_root_realpath_nchars)
 {
@@ -65,8 +75,7 @@ win32_extract_try_rpfix(u8 *rpbuf,
        size_t new_print_name_nchars;
        utf16lechar *p;
 
-       ret = parse_reparse_data(rpbuf, 8 + le16_to_cpu(*(u16*)(rpbuf + 4)),
-                                &rpdata);
+       ret = parse_reparse_data(rpbuf, *rpbuflen_p, &rpdata);
        if (ret)
                return ret;
 
@@ -110,12 +119,10 @@ win32_extract_try_rpfix(u8 *rpbuf,
                *p++ = extract_root_realpath[1];
        }
        /* Copy the rest of the extract root */
-       wmemcpy(p, extract_root_realpath + 2, extract_root_realpath_nchars - 2);
-       p += extract_root_realpath_nchars - 2;
+       p = wmempcpy(p, extract_root_realpath + 2, extract_root_realpath_nchars - 2);
 
        /* Append the stripped target */
-       wmemcpy(p, stripped_target, stripped_target_nchars);
-       p += stripped_target_nchars;
+       p = wmempcpy(p, stripped_target, stripped_target_nchars);
        new_target_nchars = p - new_target;
        new_print_name_nchars = p - new_print_name;
 
@@ -129,7 +136,7 @@ win32_extract_try_rpfix(u8 *rpbuf,
        rpdata.substitute_name_nbytes = new_target_nchars * sizeof(utf16lechar);
        rpdata.print_name = new_print_name;
        rpdata.print_name_nbytes = new_print_name_nchars * sizeof(utf16lechar);
-       return make_reparse_buffer(&rpdata, rpbuf);
+       return make_reparse_buffer(&rpdata, rpbuf, rpbuflen_p);
 }
 
 /* Wrapper around the FSCTL_SET_REPARSE_POINT ioctl to set the reparse data on
@@ -142,12 +149,13 @@ win32_set_reparse_data(HANDLE h,
                       struct apply_args *args)
 {
        int ret;
-       u8 rpbuf[REPARSE_POINT_MAX_SIZE];
+       u8 rpbuf[REPARSE_POINT_MAX_SIZE] _aligned_attribute(8);
        DWORD bytesReturned;
+       u16 rpbuflen;
 
        DEBUG("Setting reparse data on \"%ls\"", path);
 
-       ret = wim_inode_get_reparse_data(inode, rpbuf);
+       ret = wim_inode_get_reparse_data(inode, rpbuf, &rpbuflen);
        if (ret)
                return ret;
 
@@ -157,6 +165,7 @@ win32_set_reparse_data(HANDLE h,
            !inode->i_not_rpfixed)
        {
                ret = win32_extract_try_rpfix(rpbuf,
+                                             &rpbuflen,
                                              args->target_realpath,
                                              args->target_realpath_len);
                if (ret)
@@ -185,7 +194,7 @@ win32_set_reparse_data(HANDLE h,
         *  "Not used with this operation; set to NULL."
         */
        if (!DeviceIoControl(h, FSCTL_SET_REPARSE_POINT, rpbuf,
-                            8 + le16_to_cpu(*(u16*)(rpbuf + 4)),
+                            rpbuflen,
                             NULL, 0,
                             &bytesReturned /* lpBytesReturned */,
                             NULL /* lpOverlapped */))
@@ -668,7 +677,6 @@ win32_finish_extract_stream(HANDLE h, const struct wim_dentry *dentry,
 {
        int ret = 0;
        const struct wim_inode *inode = dentry->d_inode;
-       const wchar_t *short_name;
        if (stream_name_utf16 == NULL) {
                /* Unnamed stream. */
 
@@ -724,7 +732,7 @@ win32_finish_extract_stream(HANDLE h, const struct wim_dentry *dentry,
                }
 
                if (dentry_has_short_name(dentry))
-                       SetFileShortNameW(h, short_name);
+                       SetFileShortNameW(h, dentry->short_name);
                else if (running_on_windows_7_or_later())
                        SetFileShortNameW(h, L"");
        } else {