diff options
| author | Kartik Naik <kartik@bugqore.com> | 2026-07-10 02:03:58 +0530 |
|---|---|---|
| committer | Kartik Naik <kartik@bugqore.com> | 2026-07-10 02:03:58 +0530 |
| commit | 9c15b8f4ad2ae3fde714a0cd29f9e0f4a6129395 (patch) | |
| tree | 9a136f3f71322364edfd7574d6c8f4e0f7e2dc3f /include | |
| parent | a5178f345d343287eec33d422751b15e2fb58b30 (diff) | |
| download | portable-9c15b8f4ad2ae3fde714a0cd29f9e0f4a6129395.tar.gz portable-9c15b8f4ad2ae3fde714a0cd29f9e0f4a6129395.tar.bz2 portable-9c15b8f4ad2ae3fde714a0cd29f9e0f4a6129395.zip | |
guard _wopendir against unchecked GetFullPathNameW result
Diffstat (limited to 'include')
| -rw-r--r-- | include/compat/dirent_msvc.h | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/include/compat/dirent_msvc.h b/include/compat/dirent_msvc.h index 0f36803..2689399 100644 --- a/include/compat/dirent_msvc.h +++ b/include/compat/dirent_msvc.h | |||
| @@ -155,7 +155,7 @@ _wopendir(const wchar_t *dirname) | |||
| 155 | /* Allocate new _WDIR structure */ | 155 | /* Allocate new _WDIR structure */ |
| 156 | dirp =(_WDIR*) malloc(sizeof(struct _WDIR)); | 156 | dirp =(_WDIR*) malloc(sizeof(struct _WDIR)); |
| 157 | if (dirp != NULL) { | 157 | if (dirp != NULL) { |
| 158 | DWORD n; | 158 | DWORD n, len; |
| 159 | 159 | ||
| 160 | /* Reset _WDIR structure */ | 160 | /* Reset _WDIR structure */ |
| 161 | dirp->handle = INVALID_HANDLE_VALUE; | 161 | dirp->handle = INVALID_HANDLE_VALUE; |
| @@ -175,12 +175,12 @@ _wopendir(const wchar_t *dirname) | |||
| 175 | * allows rewinddir() to function correctly even when current | 175 | * allows rewinddir() to function correctly even when current |
| 176 | * working directory is changed between opendir() and rewinddir(). | 176 | * working directory is changed between opendir() and rewinddir(). |
| 177 | */ | 177 | */ |
| 178 | n = GetFullPathNameW(dirname, n, dirp->patt, NULL); | 178 | len = GetFullPathNameW(dirname, n, dirp->patt, NULL); |
| 179 | if (n > 0) { | 179 | if (len > 0 && len < n) { |
| 180 | wchar_t *p; | 180 | wchar_t *p; |
| 181 | 181 | ||
| 182 | /* Append search pattern \* to the directory name */ | 182 | /* Append search pattern \* to the directory name */ |
| 183 | p = dirp->patt + n; | 183 | p = dirp->patt + len; |
| 184 | if (dirp->patt < p) { | 184 | if (dirp->patt < p) { |
| 185 | switch(p[-1]) { | 185 | switch(p[-1]) { |
| 186 | case '\\': | 186 | case '\\': |
