From ad6ea84308f7322db8a8ea8906a47ea1cef1b725 Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Sat, 28 Dec 2013 13:47:17 -0600 Subject: [PATCH] win32_build_dentry_tree(): Fix handling of maximum length path --- src/win32_capture.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/win32_capture.c b/src/win32_capture.c index 71e6c840..bec7b3d3 100644 --- a/src/win32_capture.c +++ b/src/win32_capture.c @@ -1387,8 +1387,8 @@ win32_build_dentry_tree(struct wim_dentry **root_ret, /* 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 * by Windows NT (which is NOT the same as MAX_PATH). */ - path = MALLOC(WINDOWS_NT_MAX_PATH * sizeof(wchar_t)); - if (!path) + path = MALLOC((WINDOWS_NT_MAX_PATH + 1) * sizeof(wchar_t)); + if (path == NULL) return WIMLIB_ERR_NOMEM; /* Work around defective behavior in Windows where paths longer than 260 @@ -1396,10 +1396,10 @@ win32_build_dentry_tree(struct wim_dentry **root_ret, * turned into absolute paths and prefixed with "\\?\". */ if (wcsncmp(root_disk_path, L"\\\\?\\", 4)) { - dret = GetFullPathName(root_disk_path, WINDOWS_NT_MAX_PATH - 4, + dret = GetFullPathName(root_disk_path, WINDOWS_NT_MAX_PATH - 3, &path[4], NULL); - if (dret == 0 || dret >= WINDOWS_NT_MAX_PATH - 4) { + if (dret == 0 || dret >= WINDOWS_NT_MAX_PATH - 3) { WARNING("Can't get full path name for \"%ls\"", root_disk_path); wmemcpy(path, root_disk_path, path_nchars + 1); } else { -- 2.43.0