diff options
| author | Edward Thomson <ethomson@edwardthomson.com> | 2019-05-20 06:31:42 -0700 |
|---|---|---|
| committer | Edward Thomson <ethomson@edwardthomson.com> | 2019-06-24 15:00:40 +0100 |
| commit | d488c02c958ce23947dbd8ec541661192c8be221 (patch) | |
| tree | ce6881620cd16a4559bb1c0128f2d8387a2409bb /src/win32 | |
| parent | cadddaedc3dc6ab8e76ae4ff4a7a59ea3b3abf75 (diff) | |
| download | libgit2-d488c02c958ce23947dbd8ec541661192c8be221.tar.gz | |
win32: safely cast path sizes for win api
Diffstat (limited to 'src/win32')
| -rw-r--r-- | src/win32/path_w32.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/win32/path_w32.c b/src/win32/path_w32.c index b955b024c..eda85abf4 100644 --- a/src/win32/path_w32.c +++ b/src/win32/path_w32.c @@ -140,14 +140,24 @@ int git_win32_path_canonicalize(git_win32_path path) *to = L'\0'; - return (to - path); + if ((to - path) > INT_MAX) { + SetLastError(ERROR_FILENAME_EXCED_RANGE); + return -1; + } + + return (int)(to - path); } int git_win32_path__cwd(wchar_t *out, size_t len) { int cwd_len; - if ((cwd_len = path__cwd(out, len)) < 0) + if (len > INT_MAX) { + errno = ENAMETOOLONG; + return -1; + } + + if ((cwd_len = path__cwd(out, (int)len)) < 0) return -1; /* UNC paths */ |
