(SIGAR-192) avoid possible stack corruption in Windows proc_env impl

This commit is contained in:
Doug MacEachern 2010-04-14 13:55:57 -07:00
parent 55002f1930
commit 6c1f0a9871
1 changed files with 9 additions and 3 deletions

View File

@ -1491,7 +1491,8 @@ int sigar_os_proc_args_get(sigar_t *sigar, sigar_pid_t pid,
} }
} }
static int sigar_proc_env_parse(UCHAR *ptr, sigar_proc_env_t *procenv) static int sigar_proc_env_parse(UCHAR *ptr, sigar_proc_env_t *procenv,
int multi)
{ {
while (*ptr) { while (*ptr) {
char *val; char *val;
@ -1524,6 +1525,10 @@ static int sigar_proc_env_parse(UCHAR *ptr, sigar_proc_env_t *procenv)
return status; return status;
} }
if (!multi) {
break; /* caller only provided 1 key=val pair */
}
ptr += klen + 1 + vlen + 1; ptr += klen + 1 + vlen + 1;
} }
@ -1535,7 +1540,7 @@ static int sigar_local_proc_env_get(sigar_t *sigar, sigar_pid_t pid,
{ {
UCHAR *env = (UCHAR*)GetEnvironmentStrings(); UCHAR *env = (UCHAR*)GetEnvironmentStrings();
sigar_proc_env_parse(env, procenv); sigar_proc_env_parse(env, procenv, TRUE);
FreeEnvironmentStrings(env); FreeEnvironmentStrings(env);
@ -1564,8 +1569,9 @@ static int sigar_remote_proc_env_get(sigar_t *sigar, sigar_pid_t pid,
while ((size > 0) && (*ptr != L'\0')) { while ((size > 0) && (*ptr != L'\0')) {
DWORD len = (wcslen((LPWSTR)ptr) + 1) * sizeof(WCHAR); DWORD len = (wcslen((LPWSTR)ptr) + 1) * sizeof(WCHAR);
/* multi=FALSE so no need to: memset(ent, '\0', sizeof(ent)) */
SIGAR_W2A((WCHAR *)ptr, ent, sizeof(ent)); SIGAR_W2A((WCHAR *)ptr, ent, sizeof(ent));
if (sigar_proc_env_parse(ent, procenv) != SIGAR_OK) { if (sigar_proc_env_parse(ent, procenv, FALSE) != SIGAR_OK) {
break; break;
} }
size -= len; size -= len;