The default bug view has changed. See this FAQ.

Investigate stack buffer overflow in nsLocalFile::EnsureShortPath

RESOLVED FIXED in mozilla10

Status

()

Core
XPCOM
RESOLVED FIXED
6 years ago
6 years ago

People

(Reporter: bsterne, Assigned: bbondy)

Tracking

6 Branch
mozilla10
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Whiteboard: [sg:nse])

Attachments

(1 attachment)

(Reporter)

Description

6 years ago
Fabian Yamaguchi of Recurity Labs on behalf of BSI (German Federal Office for Information Security) reported the following to security@mozilla.org:

Method: nsLocalFile::EnsureShortPath

Component:
The bug is contained in the nsLocalFile Implementation for Windows.

Summary:
The method nsLocalFile::EnsureShortPath contains a call to GetShortPathName, which potentially overflows a stack­based buffer.

Overview:
The method nsLocalFile::EnsureShortPath reads a path name into a local stack­buffer by using the Win32 API function GetShortPathNameW. This function expects the number of wide­characters that the destination buffer can hold as its last argument. In EnsureShortPath, this third parameter has mistakenly been chosen to contain the number of bytes the buffer consists of, which is twice as much as the number of wide­characters it can hold. Therefore, it may be possible to trigger a stack­ based buffer­overflow.

Actual Results:
A local stack­buffer can potentially be overflowed.

Expected Results:
The buffer cannot be overflowed.

Additional Information:
The vulnerable code is the following.
void nsLocalFile::EnsureShortPath()
{
[...]
    WCHAR thisshort[MAX_PATH];
    DWORD thisr = ::GetShortPathNameW(mWorkingPath.get(), thisshort,
                                      sizeof(thisshort));
[...]
}
I don't think this is actually a security problem because we never use \\?\ style paths, so they cannot be longer than MAX_PATH. But we should still fix the code.
Assignee: nobody → netzen
Group: core-security
Whiteboard: [sg:nse]
(Assignee)

Comment 2

6 years ago
Created attachment 562479 [details] [diff] [review]
Buffer overflow fix
Attachment #562479 - Flags: review?(benjamin)
Attachment #562479 - Flags: review?(benjamin) → review+
(Assignee)

Comment 3

6 years ago
Pushed to try:
https://tbpl.mozilla.org/?tree=Try&usebuildbot=1&rev=d0fbb1c0ab14
(Assignee)

Comment 4

6 years ago
Pushed to inbound: 
http://hg.mozilla.org/integration/mozilla-inbound/rev/c872ba5d7b05
https://hg.mozilla.org/mozilla-central/rev/4ca939ac46fa

I accidentally pushed this patch to mozilla-central while it was living on inbound.  On the next merge, it will be merged.  Sorry for the mess!
Status: NEW → RESOLVED
Last Resolved: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla10
Merged from inbound: https://hg.mozilla.org/mozilla-central/rev/c872ba5d7b05
You need to log in before you can comment on or make changes to this bug.