Bug 1340577 - Add release-grade assertions to various XPCOM string API implementations to avoid input causing an overflow. r=froydnj

This commit is contained in:
Honza Bambas
2017-02-21 11:38:00 -05:00
parent 97186c31ff
commit aa77abdc46
8 changed files with 122 additions and 69 deletions

View File

@@ -4,6 +4,15 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
nsTDependentString_CharT::nsTDependentString_CharT(const char_type* aStart,
const char_type* aEnd)
: string_type(const_cast<char_type*>(aStart),
uint32_t(aEnd - aStart), F_TERMINATED)
{
MOZ_RELEASE_ASSERT(aStart <= aEnd, "Overflow!");
AssertValidDependentString();
}
void
nsTDependentString_CharT::Rebind(const string_type& str, uint32_t startPos)
{
@@ -23,3 +32,10 @@ nsTDependentString_CharT::Rebind(const string_type& str, uint32_t startPos)
SetDataFlags(str.Flags() & (F_TERMINATED | F_LITERAL));
}
void
nsTDependentString_CharT::Rebind(const char_type* aStart, const char_type* aEnd)
{
MOZ_RELEASE_ASSERT(aStart <= aEnd, "Overflow!");
Rebind(aStart, uint32_t(aEnd - aStart));
}