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.
Originally disclosed on Mozilla
- Fixed in 5 days
- Paid in 13 days
- Disclosed after 5 days
`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."
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.