Fabian Yamaguchi of Recurity Labs on behalf of BSI (German Federal Office for Information Security) reported the following to firstname.lastname@example.org:
The bug is contained in the nsLocalFile Implementation for Windows.
The method nsLocalFile::EnsureShortPath contains a call to GetShortPathName, which potentially overflows a stackbased buffer.
The method nsLocalFile::EnsureShortPath reads a path name into a local stackbuffer by using the Win32 API function GetShortPathNameW. This function expects the number of widecharacters 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 widecharacters it can hold. Therefore, it may be possible to trigger a stack based bufferoverflow.
A local stackbuffer can potentially be overflowed.
The buffer cannot be overflowed.
The vulnerable code is the following.
DWORD thisr = ::GetShortPathNameW(mWorkingPath.get(), 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.
Created attachment 562479 [details] [diff] [review]
Buffer overflow fix
Pushed to try:
Pushed to inbound:
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!
Merged from inbound: https://hg.mozilla.org/mozilla-central/rev/c872ba5d7b05