diff options
author | Ian Hattendorf <ianh@axosoft.com> | 2019-12-31 12:38:03 -0700 |
---|---|---|
committer | Edward Thomson <ethomson@edwardthomson.com> | 2021-05-05 23:13:35 +0100 |
commit | 69c65b9a45d5ef7e0960623f5cb3dfeaf66b09ad (patch) | |
tree | 8f46759be11b42224cf8139771af592b3b61316b /src/win32 | |
parent | 5368be3053d311cb7c65d44ce6643b5de32694ec (diff) | |
download | libgit2-69c65b9a45d5ef7e0960623f5cb3dfeaf66b09ad.tar.gz |
path: bump most Win32 unicode buffer sizes from MAX_PATH to GIT_PATH_MAX
Diffstat (limited to 'src/win32')
-rw-r--r-- | src/win32/path_w32.c | 20 | ||||
-rw-r--r-- | src/win32/w32_common.h | 27 |
2 files changed, 28 insertions, 19 deletions
diff --git a/src/win32/path_w32.c b/src/win32/path_w32.c index 23efd9269..581673b1b 100644 --- a/src/win32/path_w32.c +++ b/src/win32/path_w32.c @@ -170,7 +170,7 @@ static int win32_path_cwd(wchar_t *out, size_t len) * '\'s, but we we add a 'UNC' specifier to the path, plus * a trailing directory separator, plus a NUL. */ - if (cwd_len > MAX_PATH - 4) { + if (cwd_len > GIT_WIN_PATH_MAX - 4) { errno = ENAMETOOLONG; return -1; } @@ -187,7 +187,7 @@ static int win32_path_cwd(wchar_t *out, size_t len) * working directory. (One character for the directory separator, * one for the null. */ - else if (cwd_len > MAX_PATH - 2) { + else if (cwd_len > GIT_WIN_PATH_MAX - 2) { errno = ENAMETOOLONG; return -1; } @@ -205,13 +205,13 @@ int git_win32_path_from_utf8(git_win32_path out, const char *src) /* See if this is an absolute path (beginning with a drive letter) */ if (git_path_is_absolute(src)) { - if (git__utf8_to_16(dest, MAX_PATH, src) < 0) + if (git__utf8_to_16(dest, GIT_WIN_PATH_MAX, src) < 0) goto on_error; } /* File-prefixed NT-style paths beginning with \\?\ */ else if (path__is_nt_namespace(src)) { /* Skip the NT prefix, the destination already contains it */ - if (git__utf8_to_16(dest, MAX_PATH, src + PATH__NT_NAMESPACE_LEN) < 0) + if (git__utf8_to_16(dest, GIT_WIN_PATH_MAX, src + PATH__NT_NAMESPACE_LEN) < 0) goto on_error; } /* UNC paths */ @@ -220,12 +220,12 @@ int git_win32_path_from_utf8(git_win32_path out, const char *src) dest += 4; /* Skip the leading "\\" */ - if (git__utf8_to_16(dest, MAX_PATH - 2, src + 2) < 0) + if (git__utf8_to_16(dest, GIT_WIN_PATH_MAX - 2, src + 2) < 0) goto on_error; } /* Absolute paths omitting the drive letter */ else if (path__startswith_slash(src)) { - if (path__cwd(dest, MAX_PATH) < 0) + if (path__cwd(dest, GIT_WIN_PATH_MAX) < 0) goto on_error; if (!git_path_is_absolute(dest)) { @@ -234,19 +234,19 @@ int git_win32_path_from_utf8(git_win32_path out, const char *src) } /* Skip the drive letter specification ("C:") */ - if (git__utf8_to_16(dest + 2, MAX_PATH - 2, src) < 0) + if (git__utf8_to_16(dest + 2, GIT_WIN_PATH_MAX - 2, src) < 0) goto on_error; } /* Relative paths */ else { int cwd_len; - if ((cwd_len = win32_path_cwd(dest, MAX_PATH)) < 0) + if ((cwd_len = win32_path_cwd(dest, GIT_WIN_PATH_MAX)) < 0) goto on_error; dest[cwd_len++] = L'\\'; - if (git__utf8_to_16(dest + cwd_len, MAX_PATH - cwd_len, src) < 0) + if (git__utf8_to_16(dest + cwd_len, GIT_WIN_PATH_MAX - cwd_len, src) < 0) goto on_error; } @@ -273,7 +273,7 @@ int git_win32_path_relative_from_utf8(git_win32_path out, const char *src) return git_win32_path_from_utf8(out, src); } - if ((len = git__utf8_to_16(dest, MAX_PATH, src)) < 0) + if ((len = git__utf8_to_16(dest, GIT_WIN_PATH_MAX, src)) < 0) return -1; for (p = dest; p < (dest + len); p++) { diff --git a/src/win32/w32_common.h b/src/win32/w32_common.h index f9e74b947..c20b3e85e 100644 --- a/src/win32/w32_common.h +++ b/src/win32/w32_common.h @@ -8,24 +8,33 @@ #ifndef INCLUDE_win32_w32_common_h__ #define INCLUDE_win32_w32_common_h__ +#include <git2/common.h> + +/* + * 4096 is the max allowed Git path. `MAX_PATH` (260) is the typical max allowed + * Windows path length, however win32 Unicode APIs generally allow up to 32,767 + * if prefixed with "\\?\" (i.e. converted to an NT-style name). + */ +#define GIT_WIN_PATH_MAX GIT_PATH_MAX + /* - * Provides a large enough buffer to support Windows paths: MAX_PATH is - * 260, corresponding to a maximum path length of 259 characters plus a - * NULL terminator. Prefixing with "\\?\" adds 4 characters, but if the - * original was a UNC path, then we turn "\\server\share" into + * Provides a large enough buffer to support Windows Git paths: + * GIT_WIN_PATH_MAX is 4096, corresponding to a maximum path length of 4095 + * characters plus a NULL terminator. Prefixing with "\\?\" adds 4 characters, + * but if the original was a UNC path, then we turn "\\server\share" into * "\\?\UNC\server\share". So we replace the first two characters with - * 8 characters, a net gain of 6, so the maximum length is MAX_PATH+6. + * 8 characters, a net gain of 6, so the maximum length is GIT_WIN_PATH_MAX+6. */ -#define GIT_WIN_PATH_UTF16 MAX_PATH+6 +#define GIT_WIN_PATH_UTF16 GIT_WIN_PATH_MAX+6 -/* Maximum size of a UTF-8 Win32 path. We remove the "\\?\" or "\\?\UNC\" - * prefixes for presentation, bringing us back to 259 (non-NULL) +/* Maximum size of a UTF-8 Win32 Git path. We remove the "\\?\" or "\\?\UNC\" + * prefixes for presentation, bringing us back to 4095 (non-NULL) * characters. UTF-8 does have 4-byte sequences, but they are encoded in * UTF-16 using surrogate pairs, which takes up the space of two characters. * Two characters in the range U+0800 -> U+FFFF take up more space in UTF-8 * (6 bytes) than one surrogate pair (4 bytes). */ -#define GIT_WIN_PATH_UTF8 (259 * 3 + 1) +#define GIT_WIN_PATH_UTF8 ((GIT_WIN_PATH_MAX - 1) * 3 + 1) /* * The length of a Windows "shortname", for 8.3 compatibility. |