Bug 1330759 part 2. Fix XPCConvert::JSData2Native to not share an external string stringbuffer if it would create a non-null-terminated string. r=froydnj

This commit is contained in:
Boris Zbarsky 2017-01-18 22:20:14 -05:00
Родитель 10ac0b56b4
Коммит ced1c6138f
1 изменённых файлов: 7 добавлений и 1 удалений

Просмотреть файл

@ -524,7 +524,13 @@ XPCConvert::JSData2Native(void* d, HandleValue s,
// The characters represent an existing nsStringBuffer that
// was shared by XPCStringConvert::ReadableToJSVal.
const char16_t* chars = JS_GetTwoByteExternalStringChars(str);
nsStringBuffer::FromData((void*)chars)->ToString(length, *ws);
if (chars[length] == '\0') {
// Safe to share the buffer.
nsStringBuffer::FromData((void*)chars)->ToString(length, *ws);
} else {
// We have to copy to ensure null-termination.
ws->Assign(chars, length);
}
} else if (XPCStringConvert::IsLiteral(str)) {
// The characters represent a literal char16_t string constant
// compiled into libxul, such as the string "undefined" above.