Module: wine Branch: master Commit: d812af3f12434a4671f1aa98fcc5fb11ffa9826b URL: https://gitlab.winehq.org/wine/wine/-/commit/d812af3f12434a4671f1aa98fcc5fb1...
Author: Piotr Caban piotr@codeweavers.com Date: Wed Feb 15 13:38:38 2023 +0100
msvcrt: Don't crash on NULL argument in _wgetenv.
---
dlls/msvcrt/environ.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/dlls/msvcrt/environ.c b/dlls/msvcrt/environ.c index 145f7d0640f..a2626a85c30 100644 --- a/dlls/msvcrt/environ.c +++ b/dlls/msvcrt/environ.c @@ -50,12 +50,15 @@ char * CDECL getenv(const char *name) }
/********************************************************************* - * _wgetenv (MSVCRT.@) + * _wgetenv (MSVCRT.@) */ wchar_t * CDECL _wgetenv(const wchar_t *name) { wchar_t **env; - unsigned int length=wcslen(name); + size_t len; + + if (!MSVCRT_CHECK_PMT(name != NULL)) return NULL; + len = wcslen(name);
/* Initialize the _wenviron array if it's not already created. */ if (!MSVCRT__wenviron) @@ -65,7 +68,7 @@ wchar_t * CDECL _wgetenv(const wchar_t *name) { wchar_t *str = *env; wchar_t *pos = wcschr(str,'='); - if (pos && ((pos - str) == length) && !_wcsnicmp(str,name,length)) + if (pos && ((pos - str) == len) && !_wcsnicmp(str, name, len)) { TRACE("(%s): got %s\n", debugstr_w(name), debugstr_w(pos + 1)); return pos + 1;