Commit 048b3ac6 authored by Alexandre Julliard's avatar Alexandre Julliard

Fixed RtlSetEnvironmentVariable to deal properly with Unicode strings

that aren't null-terminated.
parent 4e5b9efc
...@@ -181,10 +181,14 @@ NTSTATUS WINAPI RtlSetEnvironmentVariable(PWSTR* penv, PUNICODE_STRING name, ...@@ -181,10 +181,14 @@ NTSTATUS WINAPI RtlSetEnvironmentVariable(PWSTR* penv, PUNICODE_STRING name,
penv, debugstr_w(name->Buffer), penv, debugstr_w(name->Buffer),
value ? debugstr_w(value->Buffer) : "--nil--"); value ? debugstr_w(value->Buffer) : "--nil--");
if (!name || !name->Buffer || !name->Buffer[0]) if (!name || !name->Buffer || !name->Length)
return STATUS_INVALID_PARAMETER_1; return STATUS_INVALID_PARAMETER_1;
len = name->Length / sizeof(WCHAR);
/* variable names can't contain a '=' except as a first character */ /* variable names can't contain a '=' except as a first character */
if (strchrW(name->Buffer + 1, '=')) return STATUS_INVALID_PARAMETER; for (p = name->Buffer + 1; p < name->Buffer + len; p++)
if (*p == '=') return STATUS_INVALID_PARAMETER;
if (!penv) if (!penv)
{ {
...@@ -192,8 +196,6 @@ NTSTATUS WINAPI RtlSetEnvironmentVariable(PWSTR* penv, PUNICODE_STRING name, ...@@ -192,8 +196,6 @@ NTSTATUS WINAPI RtlSetEnvironmentVariable(PWSTR* penv, PUNICODE_STRING name,
env = NtCurrentTeb()->Peb->ProcessParameters->Environment; env = NtCurrentTeb()->Peb->ProcessParameters->Environment;
} else env = *penv; } else env = *penv;
len = name->Length / sizeof(WCHAR);
/* compute current size of environment */ /* compute current size of environment */
for (p = env; *p; p += strlenW(p) + 1); for (p = env; *p; p += strlenW(p) + 1);
old_size = p + 1 - env; old_size = p + 1 - env;
...@@ -247,11 +249,11 @@ NTSTATUS WINAPI RtlSetEnvironmentVariable(PWSTR* penv, PUNICODE_STRING name, ...@@ -247,11 +249,11 @@ NTSTATUS WINAPI RtlSetEnvironmentVariable(PWSTR* penv, PUNICODE_STRING name,
/* Set the new string */ /* Set the new string */
if (value) if (value)
{ {
static const WCHAR equalW[] = {'=',0}; memcpy( p, name->Buffer, name->Length );
p += name->Length / sizeof(WCHAR);
strcpyW(p, name->Buffer); *p++ = '=';
strcatW(p, equalW); memcpy( p, value->Buffer, value->Length );
strcatW(p, value->Buffer); p[value->Length / sizeof(WCHAR)] = 0;
} }
done: done:
if (!penv) RtlReleasePebLock(); if (!penv) RtlReleasePebLock();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment