MSVCRT_getenv: compare for the length of the key and return NULL in

case of failure.
This commit is contained in:
Uwe Bonnes 2001-11-23 18:30:19 +00:00 committed by Alexandre Julliard
parent dc3fa49bc3
commit b35d86aa13
1 changed files with 24 additions and 21 deletions

View File

@ -21,22 +21,23 @@ char *MSVCRT_getenv(const char *name)
{ {
char *environ = GetEnvironmentStringsA(); char *environ = GetEnvironmentStringsA();
char *pp,*pos = NULL; char *pp,*pos = NULL;
unsigned int length; unsigned int length=strlen(name);
for (pp = environ; (*pp); pp = pp + strlen(pp) +1) for (pp = environ; (*pp); pp = pp + strlen(pp) +1)
{ {
pos =strchr(pp,'='); pos =strchr(pp,'=');
if (pos) if ((pos) && ((pos - pp) == length))
length = pos -pp; {
else
length = strlen(pp);
if (!strncmp(pp,name,length)) break; if (!strncmp(pp,name,length)) break;
} }
if ((pp)&& (pos)) }
if ((*pp)&& (pos))
{ {
pp = pos+1; pp = pos+1;
TRACE("got %s\n",pp); TRACE("got %s\n",pp);
} }
else
pp = 0;
FreeEnvironmentStringsA( environ ); FreeEnvironmentStringsA( environ );
return pp; return pp;
} }
@ -48,24 +49,26 @@ WCHAR *_wgetenv(const WCHAR *name)
{ {
WCHAR* environ = GetEnvironmentStringsW(); WCHAR* environ = GetEnvironmentStringsW();
WCHAR* pp,*pos = NULL; WCHAR* pp,*pos = NULL;
unsigned int length; unsigned int length=strlenW(name);
for (pp = environ; (*pp); pp = pp + strlenW(pp) + 1) for (pp = environ; (*pp); pp = pp + strlenW(pp) + 1)
{ {
pos = strrchrW(pp,'='); pos = strchrW(pp,'=');
if (pos) if ((pos) && ((pos - pp) == length))
length = pos -pp; {
else if (!strncmpW(pp,name,length))
length = strlenW(pp);
if (!strncmpW(pp,name,length)) break;
}
if ((pp)&& (pos))
{ {
pp = pos+1; pp = pos+1;
TRACE("got %s\n",debugstr_w(pp)); TRACE("got %s\n",debugstr_w(pp));
/* can't free pointer since we are returning it */
/* should probably use MSVCRT_wenviron instead */
FIXME( "memory leak\n" );
return pp;
}
}
} }
FreeEnvironmentStringsW( environ ); FreeEnvironmentStringsW( environ );
return pp; return NULL;
} }
/********************************************************************* /*********************************************************************