aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo Buehler <tb@openbsd.org>2026-07-10 08:24:29 +0200
committerTheo Buehler <tb@openbsd.org>2026-07-10 08:24:29 +0200
commit62858a6ba717bcadbcbf9135ba5873f017162c7d (patch)
tree9a136f3f71322364edfd7574d6c8f4e0f7e2dc3f
parenta5178f345d343287eec33d422751b15e2fb58b30 (diff)
parent9c15b8f4ad2ae3fde714a0cd29f9e0f4a6129395 (diff)
downloadportable-62858a6ba717bcadbcbf9135ba5873f017162c7d.tar.gz
portable-62858a6ba717bcadbcbf9135ba5873f017162c7d.tar.bz2
portable-62858a6ba717bcadbcbf9135ba5873f017162c7d.zip
Land #1316 - properly check GetFullPathNameW
-rw-r--r--include/compat/dirent_msvc.h8
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 '\\':