Bug 936886 - Account for possibility of non-null terminated strings in nsWindowsRegKey::ReadStringValue(). r=dmajor

This commit is contained in:
James Kitchener 2013-11-19 09:09:41 -05:00
parent fd3ed78a40
commit 8d6c5dce65

View File

@ -287,8 +287,8 @@ nsWindowsRegKey::ReadStringValue(const nsAString &name, nsAString &result)
return NS_OK;
}
// |size| includes room for the terminating null character
DWORD resultLen = size / 2 - 1;
// |size| may or may not include the terminating null character.
DWORD resultLen = size / 2;
result.SetLength(resultLen);
nsAString::iterator begin;
@ -299,6 +299,11 @@ nsWindowsRegKey::ReadStringValue(const nsAString &name, nsAString &result)
rv = RegQueryValueExW(mKey, flatName.get(), 0, &type, (LPBYTE) begin.get(),
&size);
if (!result.CharAt(resultLen-1)) {
// The string passed to us had a null terminator in the final position.
result.Truncate(resultLen-1);
}
// Expand the environment variables if needed
if (type == REG_EXPAND_SZ) {
const nsString &flatSource = PromiseFlatString(result);