diff options
author | 2017-02-07 09:51:58 +0000 | |
---|---|---|
committer | 2017-02-07 18:26:57 +0000 | |
commit | d657d7b5bd24e2c7411828b9652152cbb479a3a9 (patch) | |
tree | c39e810ac9055e176f6efc05ec3fff4861059230 /src/main/java/com/google/devtools/build/lib/windows | |
parent | 8e0991cb19eadfcb651cd6987255d5f7c0a58e0a (diff) |
Windows: fix off-by-one errors with MAX_PATH
In almost every place we compared paths against
MAX_PATH, we had it wrong. MAX_PATH is the
null-terminated maximum length, so paths exactly
MAX_PATH long (not counting the null-terminator)
were incorrectly considered short.
Also fix the error message in the MSVC python
wrapper, because it reported an incorrect path
length limit in the warning message.
See https://github.com/bazelbuild/bazel/issues/2107
--
PiperOrigin-RevId: 146762382
MOS_MIGRATED_REVID=146762382
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/windows')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/windows/WindowsFileOperations.java | 8 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/windows/WindowsSubprocessFactory.java | 4 |
2 files changed, 7 insertions, 5 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/windows/WindowsFileOperations.java b/src/main/java/com/google/devtools/build/lib/windows/WindowsFileOperations.java index 516c29ec0e..4750ff5962 100644 --- a/src/main/java/com/google/devtools/build/lib/windows/WindowsFileOperations.java +++ b/src/main/java/com/google/devtools/build/lib/windows/WindowsFileOperations.java @@ -42,6 +42,8 @@ public class WindowsFileOperations { // Prevent construction } + private static final int MAX_PATH = 260; + // Keep IS_JUNCTION_* values in sync with src/main/native/windows_file_operations.cc. private static final int IS_JUNCTION_YES = 0; private static final int IS_JUNCTION_NO = 1; @@ -91,11 +93,11 @@ public class WindowsFileOperations { /** * Returns a Windows-style path suitable to pass to unicode WinAPI functions. * - * <p>Returns an UNC path if `path` is longer than `MAX_PATH` (in <windows.h>). If it's shorter or - * is already an UNC path, then this method returns `path` itself. + * <p>Returns an UNC path if `path` is at least `MAX_PATH` long. If it's shorter or is already an + * UNC path, then this method returns `path` itself. */ static String asLongPath(String path) { - return path.length() > 260 && !path.startsWith("\\\\?\\") + return path.length() >= MAX_PATH && !path.startsWith("\\\\?\\") ? ("\\\\?\\" + path.replace('/', '\\')) : path; } diff --git a/src/main/java/com/google/devtools/build/lib/windows/WindowsSubprocessFactory.java b/src/main/java/com/google/devtools/build/lib/windows/WindowsSubprocessFactory.java index ae8b495cfd..0632baca01 100644 --- a/src/main/java/com/google/devtools/build/lib/windows/WindowsSubprocessFactory.java +++ b/src/main/java/com/google/devtools/build/lib/windows/WindowsSubprocessFactory.java @@ -69,8 +69,8 @@ public class WindowsSubprocessFactory implements Subprocess.Factory { public String processArgv0(String argv0) { // Normalize the path and make it Windows-style. - // If argv0 is longer than MAX_PATH (260 chars), createNativeProcess calls GetShortPathNameW to - // obtain a 8dot3 name for it (thereby support long paths in CreateProcessA), but then argv0 + // If argv0 is at least MAX_PATH (260 chars) long, createNativeProcess calls GetShortPathNameW + // to obtain a 8dot3 name for it (thereby support long paths in CreateProcessA), but then argv0 // must be prefixed with "\\?\" for GetShortPathNameW to work, so it also must be an absolute, // normalized, Windows-style path. // Therefore if it's absolute, then normalize it also. |