Overflow in nsXMLHttpRequest::AppendToResponseText causes memory-safety bug
- Fixed in 22 days
- Paid in 27 days
- Disclosed after 22 days
User Agent: Mozilla/5.0 (Windows NT 5.1; rv:36.0) Gecko/20100101 Firefox/36.0
Build ID: 20150305021524
Steps to reproduce:
nsXMLHttpRequest::AppendToResponseText (38.0.1\dom\base\nsXMLHttpRequest.cpp) can write to memory that it does not own:
665: nsresult
666: nsXMLHttpRequest::AppendToResponseText(const char * aSrcBuffer,
667: uint32_t aSrcBufferLen)
668: {
669: NS_ENSURE_STATE(mDecoder);
670:
671: int32_t destBufferLen;
672: nsresult rv = mDecoder->GetMaxLength(aSrcBuffer, aSrcBufferLen,
673: &destBufferLen);
674: NS_ENSURE_SUCCESS(rv, rv);
675:
676: if (!mResponseText.SetCapacity(mResponseText.Length() + destBufferLen, fallible)) {
677: return NS_ERROR_OUT_OF_MEMORY;
678: }
679:
680: char16_t* destBuffer = mResponseText.BeginWriting() + mResponseText.Length();
681:
682: int32_t totalChars = mResponseText.Length();
683:
684: // This code here is basically a copy of a similar thing in
685: // nsScanner::Append(const char* aBuffer, uint32_t aLen).
686: int32_t srclen = (int32_t)aSrcBufferLen;
687: int32_t destlen = (int32_t)destBufferLen;
688: rv = mDecoder->Convert(aSrcBuffer,
689: &srclen,
690: destBuffer,
691: &destlen);
692: ...
The bug is in line 676. If mResponseText.Length() + destBufferLen overflows, line 676 will SetCapacity to a value smaller than mResponseText's current length. The remaining code will then write data beginning at the _end_ of the buffer (mResponseText.BeginWriting() + mResponseText.Length()).
Since the response text from an XMLHttpRequest is under external control, this bug could be leveraged to corrupt Firefox's address space, possibly causing execution of attacker-chosen code.
Presumably this problem can occur only under 64-bit OSes.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
What is known
A critical-severity memory corruption bug in DOM: Core & HTML. Mozilla made it public on 24 June 2015 as CVE-2015-2740.
About Memory corruption
Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
What is Memory corruption?
Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.