Skip to content
Memory corruption Disclosed report Advanced

Out-of-bounds access in nsWebBrowser::RemoveWebBrowserListener()

The RemoveWebBrowserListener function reads and potentially removes an element one past the end of its listener array due to an off-by-one error. This could cause a jump to an incorrect address and corrupt memory far beyond the array.

q1 Follow

Originally disclosed on Mozilla

  • Fixed in 14 days
  • Paid in 20 days
  • Disclosed after 14 days
Text
nsWebBrowser::RemoveWebBrowserListener() (embedding\browser\nsWebBrowser.cpp) reads (and, if the element read contains exactly the right garbage) removes an element one beyond the end of its |mListenerArray| array,

This bug could cause a jump to an incorrect address, because removing the element invokes its type's destructor, which (because the type eventually contains a |nsIWeakReference|), eventually calls the virtual function |nsISupports::Release()|. Since the element is beyond the array's end, it almost certainly contains an incorrect virtual function table pointer, which the generated code will use to call what should be the implementation of nsISupports::Release(), but which instead almost certainly will be code in some other function.

Also removing an element beyond the array's end will corrupt the array and memory far beyond its end (see nsTArray_base::ShiftData(), which gets invoked as part of the removal).


The bug is in lines 248-49, which use |count| instead of |count-1|:


230: NS_IMETHODIMP
231: nsWebBrowser::RemoveWebBrowserListener(nsIWeakReference* aListener,
232:                                        const nsIID& aIID)
233: {
234:   NS_ENSURE_ARG_POINTER(aListener);
235: 
236:   nsresult rv = NS_OK;
237:   if (!mWebProgress) {
238:     // if there's no-one to register the listener w/, and we don't have a queue
239:     // going, the the called is calling Remove before an Add which doesn't make
240:     // sense.
241:     if (!mListenerArray) {
242:       return NS_ERROR_FAILURE;
243:     }
244: 
245:     // iterate the array and remove the queued listener
246:     int32_t count = mListenerArray->Length();
247:     while (count > 0) {
248:       if (mListenerArray->ElementAt(count).Equals(aListener, aIID)) {
249:         mListenerArray->RemoveElementAt(count);
250:         break;
251:       }
252:       count--;
253:     }

The bug is still present in trunk.

The original report as published on Mozilla's Bugzilla, by q1. Images and videos are our own copies; raw HTML is shown as text. View it on Mozilla's Bugzilla.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The loop uses the array length as an index instead of length minus one, causing an out-of-bounds access.

Impact

This bug could cause a jump to an incorrect address and corrupt memory far beyond the array's end.

What the attacker needed

None

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

An array is a list of items stored in memory. The code tries to remove an item from the list but uses the wrong position number, so it looks at a spot just past the end of the list. That spot may contain random data, and treating it as a real item can crash the program or let an attacker run harmful code.

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.

More by q1

View all

71 more disclosed reports, best first.

More from Mozilla

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.