From 9c15b8f4ad2ae3fde714a0cd29f9e0f4a6129395 Mon Sep 17 00:00:00 2001 From: Kartik Naik Date: Fri, 10 Jul 2026 02:03:58 +0530 Subject: guard _wopendir against unchecked GetFullPathNameW result --- include/compat/dirent_msvc.h | 8 ++++---- 1 file 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) /* Allocate new _WDIR structure */ dirp =(_WDIR*) malloc(sizeof(struct _WDIR)); if (dirp != NULL) { - DWORD n; + DWORD n, len; /* Reset _WDIR structure */ dirp->handle = INVALID_HANDLE_VALUE; @@ -175,12 +175,12 @@ _wopendir(const wchar_t *dirname) * allows rewinddir() to function correctly even when current * working directory is changed between opendir() and rewinddir(). */ - n = GetFullPathNameW(dirname, n, dirp->patt, NULL); - if (n > 0) { + len = GetFullPathNameW(dirname, n, dirp->patt, NULL); + if (len > 0 && len < n) { wchar_t *p; /* Append search pattern \* to the directory name */ - p = dirp->patt + n; + p = dirp->patt + len; if (dirp->patt < p) { switch(p[-1]) { case '\\': -- cgit v1.2.3-55-g6feb