win32_capture.c: Fix exclusion when capture path ends in slash
authorEric Biggers <ebiggers3@gmail.com>
Sat, 28 Jun 2014 23:32:32 +0000 (18:32 -0500)
committerEric Biggers <ebiggers3@gmail.com>
Sat, 28 Jun 2014 23:32:32 +0000 (18:32 -0500)
Broken by e9aed5bf5c3296f35ff7007cb1702c07b7dc2b37

src/win32_capture.c

index 4bccfa1..08a0654 100644 (file)
@@ -1396,6 +1396,7 @@ win32_build_dentry_tree(struct wim_dentry **root_ret,
        int ret;
        UNICODE_STRING ntpath;
        struct winnt_scan_stats stats;
+       size_t ntpath_nchars;
 
        /* WARNING: There is no check for overflow later when this buffer is
         * being used!  But it's as long as the maximum path length understood
@@ -1417,16 +1418,20 @@ win32_build_dentry_tree(struct wim_dentry **root_ret,
                goto out_free_path;
        }
 
-       params->capture_root_nchars = ntpath.Length / sizeof(wchar_t);
-       wmemcpy(path, ntpath.Buffer, params->capture_root_nchars);
-       path[params->capture_root_nchars] = L'\0';
+       ntpath_nchars = ntpath.Length / sizeof(wchar_t);
+       wmemcpy(path, ntpath.Buffer, ntpath_nchars);
+       path[ntpath_nchars] = L'\0';
+
+       params->capture_root_nchars = ntpath_nchars;
+       if (path[ntpath_nchars - 1] == L'\\')
+               params->capture_root_nchars--;
 
        HeapFree(GetProcessHeap(), 0, ntpath.Buffer);
 
        memset(&stats, 0, sizeof(stats));
 
        ret = winnt_build_dentry_tree_recursive(root_ret, NULL,
-                                               path, params->capture_root_nchars,
+                                               path, ntpath_nchars,
                                                L"", 0, params, &stats, 0);
 out_free_path:
        FREE(path);