diff options
| author | Theo Buehler <tb@openbsd.org> | 2026-06-15 09:00:01 +0200 |
|---|---|---|
| committer | Theo Buehler <tb@openbsd.org> | 2026-06-15 09:00:01 +0200 |
| commit | f26e53bae3b409ca3f94d74d8adc382d6b8d0178 (patch) | |
| tree | bc219b86bc6d9b09f500dc84dca559a954268ae6 | |
| parent | b1034608a6d44a9b2ffc54506763657852d6b827 (diff) | |
| parent | 429bceda74c007bde07af0dd831896644b5fc7e7 (diff) | |
| download | portable-f26e53bae3b409ca3f94d74d8adc382d6b8d0178.tar.gz portable-f26e53bae3b409ca3f94d74d8adc382d6b8d0178.tar.bz2 portable-f26e53bae3b409ca3f94d74d8adc382d6b8d0178.zip | |
Land #1304 - add overflow check to MSVC dirent compat
| -rw-r--r-- | include/compat/dirent_msvc.h | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/include/compat/dirent_msvc.h b/include/compat/dirent_msvc.h index 67f295f..0f36803 100644 --- a/include/compat/dirent_msvc.h +++ b/include/compat/dirent_msvc.h | |||
| @@ -47,6 +47,7 @@ | |||
| 47 | 47 | ||
| 48 | #include <stdarg.h> | 48 | #include <stdarg.h> |
| 49 | #include <sys/stat.h> | 49 | #include <sys/stat.h> |
| 50 | #include <stdint.h> | ||
| 50 | 51 | ||
| 51 | /* Indicates that d_type field is available in dirent structure */ | 52 | /* Indicates that d_type field is available in dirent structure */ |
| 52 | #define _DIRENT_HAVE_D_TYPE | 53 | #define _DIRENT_HAVE_D_TYPE |
| @@ -165,7 +166,8 @@ _wopendir(const wchar_t *dirname) | |||
| 165 | n = GetFullPathNameW(dirname, 0, NULL, NULL); | 166 | n = GetFullPathNameW(dirname, 0, NULL, NULL); |
| 166 | 167 | ||
| 167 | /* Allocate room for absolute directory name and search pattern */ | 168 | /* Allocate room for absolute directory name and search pattern */ |
| 168 | dirp->patt =(wchar_t*) malloc(sizeof(wchar_t) * n + 16); | 169 | if (n <= (SIZE_MAX - 16) / sizeof(wchar_t)) |
| 170 | dirp->patt =(wchar_t*) malloc(sizeof(wchar_t) * n + 16); | ||
| 169 | if (dirp->patt) { | 171 | if (dirp->patt) { |
| 170 | 172 | ||
| 171 | /* | 173 | /* |
| @@ -214,6 +216,7 @@ _wopendir(const wchar_t *dirname) | |||
| 214 | 216 | ||
| 215 | } else { | 217 | } else { |
| 216 | /* Cannot allocate memory for search pattern */ | 218 | /* Cannot allocate memory for search pattern */ |
| 219 | _set_errno(ENOMEM); | ||
| 217 | error = 1; | 220 | error = 1; |
| 218 | } | 221 | } |
| 219 | 222 | ||
