Buffer overrun in GetWindowsFolder
Categories
(Core :: XPCOM, defect)
Tracking
()
People
(Reporter: away, Assigned: away)
Details
(Keywords: csectype-bounds, sec-moderate, Whiteboard: [post-critsmash-triage][adv-main83+r])
Attachments
(1 file)
The SHGetSpecialFolderPathW API returns a BOOL value but we are treating it as HRESULT: https://searchfox.org/mozilla-central/rev/f27594d62e7f1d57626889255ce6a3071d67209f/xpcom/io/SpecialSystemDirectory.cpp#72
Unfortunately, they are both just aliases for some integer type, so the compiler doesn't complain about the mixup. More unfortunately, the two types have the opposite semantics for whether zero means success.
If the call fails, we'll mistakenly continue execution, and the uninitialized path will give a garbage value of len from wcslen(path). Then writing the trailing slash to path[len] can overrun the buffer.
This appears to have originally landed in CVS in 2003 and survived several refactorings: https://github.com/mozilla/gecko-dev/commit/34cd7b0fdbb012410f261f0d85aa71f8179497b3#diff-11b97e1fdc3d3142074da11d7be9a42aR192
It seems unlikely that the overrun would happen in practice, because any null char in the uninitialized garbage of path would make wcslen give an acceptable result. Things would only go wrong if we re-used a 256-char area of stack that didn't have a single null. That doesn't seem likely in shipping builds, but in debug builds it happens 100% reliably due to our use of -ftrivial-auto-var-init=pattern to fill stack buffers with 0xAA: https://searchfox.org/mozilla-central/rev/f27594d62e7f1d57626889255ce6a3071d67209f/build/moz.configure/toolchain.configure#1643
Updated•5 years ago
|
Comment 2•5 years ago
|
||
I guess I'll mark this sec-moderate if you don't think it is an issue in practice. Thanks for filing the bug and working on it.
Comment 3•5 years ago
|
||
Comment 4•5 years ago
|
||
Updated•5 years ago
|
Comment 5•5 years ago
|
||
Given comment 2, it doesn't sound like this is something we need to worry about uplifting to ESR.
Updated•5 years ago
|
Updated•4 years ago
|
Description
•