msvcrt: Don't crash on NULL argument in getenv.

This commit is contained in:
Piotr Caban 2023-02-15 13:37:52 +01:00 committed by Alexandre Julliard
parent 887e72b24e
commit 86fb5c7ba6

View file

@ -26,18 +26,21 @@
WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
/*********************************************************************
* getenv (MSVCRT.@)
* getenv (MSVCRT.@)
*/
char * CDECL getenv(const char *name)
{
char **env;
unsigned int length=strlen(name);
size_t len;
if (!MSVCRT_CHECK_PMT(name != NULL)) return NULL;
len = strlen(name);
for (env = MSVCRT__environ; *env; env++)
{
char *str = *env;
char *pos = strchr(str,'=');
if (pos && ((pos - str) == length) && !_strnicmp(str,name,length))
if (pos && ((pos - str) == len) && !_strnicmp(str, name, len))
{
TRACE("(%s): got %s\n", debugstr_a(name), debugstr_a(pos + 1));
return pos + 1;