Skip to content
Memory corruption Disclosed report Advanced

undefined behavior with gNeuteredWindows delete in MessageChannel::SyncStackFrame()

The code deletes an object through a base-class pointer that lacks a virtual destructor, while the actual object is of a derived class. This is undefined behaviour and could lead to memory corruption or crashes.

mozillabugs Follow

Originally disclosed on Mozilla

  • Fixed in 5 days
  • Paid in 13 days
  • Disclosed after 5 days
Text
`MessageChannel::SyncStackFrame()` (`ipc/glue/WindowsMessageLoop.cpp`) invokes undefined behavior by deleting an object whose static type lacks a virtual destructor, where the object has a derived-class dynamic type. [1] The base class involved is `nsTArray`, and the derived class is `AutoTArray`.

The base-class object pointer is defined thusly (line numbers from current trunk)

'''
92: nsTArray<HWND>* gNeuteredWindows = nullptr;
'''

and the new expression:

'''
621: MessageChannel::SyncStackFrame::SyncStackFrame(MessageChannel* channel)
...
638:     gNeuteredWindows = new AutoTArray<HWND, 20>();
'''

and the delete expression:

'''
643: MessageChannel::SyncStackFrame::~SyncStackFrame() {
...
658:     delete gNeuteredWindows;
'''

[1] See C++ 20 Standard (n4750) s.8.5.2.5(3) : "In a single-object delete expression, if the static type of the object to be deleted is different from its dynamic type, the static type shall be a base class of the dynamic type of the object to be deleted and the static type shall have a virtual destructor or the behavior is undefined."

The original report as published on Mozilla's Bugzilla, by mozillabugs. 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

Likely the base class nsTArray lacks a virtual destructor, so deleting a derived AutoTArray object through an nsTArray pointer is undefined behaviour.

Impact

This undefined behaviour could cause memory corruption or crashes, though the text does not describe a specific exploit scenario.

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.

In C++, when you delete an object through a pointer to a base class, the base class must have a virtual destructor if the real object is of a derived class. Otherwise the program's behaviour is undefined, meaning it might crash or corrupt memory. Here the base class nsTArray does not have a virtual destructor, but the code deletes an AutoTArray object through an nsTArray pointer.

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 mozillabugs

View all

41 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.