mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-11 01:57:00 +00:00
Bug 419326 Crashes in Main Tab of Options [@ _wgetdcwd - nsLocalFile::Normalize] r=bsmedberg a=beltzner
This commit is contained in:
parent
620272feeb
commit
8b7c01dfff
@ -1145,6 +1145,24 @@ nsLocalFile::Normalize()
|
||||
WCHAR cwd[MAX_PATH];
|
||||
WCHAR * pcwd = cwd;
|
||||
int drive = TOUPPER(path.First()) - 'A' + 1;
|
||||
/* We need to worry about IPH, for details read bug 419326.
|
||||
* _getdrives - http://msdn2.microsoft.com/en-us/library/xdhk0xd2.aspx
|
||||
* uses a bitmask, bit 0 is 'a:'
|
||||
* _chdrive - http://msdn2.microsoft.com/en-us/library/0d1409hb.aspx
|
||||
* _getdcwd - http://msdn2.microsoft.com/en-us/library/7t2zk3s4.aspx
|
||||
* take an int, 1 is 'a:'.
|
||||
*
|
||||
* Because of this, we need to do some math. Subtract 1 to convert from
|
||||
* _chdrive/_getdcwd format to _getdrives drive numbering.
|
||||
* Shift left x bits to convert from integer indexing to bitfield indexing.
|
||||
* And of course, we need to find out if the drive is in the bitmask.
|
||||
*
|
||||
* If we're really unlucky, we can still lose, but only if the user
|
||||
* manages to eject the drive between our call to _getdrives() and
|
||||
* our *calls* to _wgetdcwd.
|
||||
*/
|
||||
if (!((1 << (drive - 1)) & _getdrives()))
|
||||
return NS_ERROR_FILE_INVALID_PATH;
|
||||
if (!_wgetdcwd(drive, pcwd, MAX_PATH))
|
||||
pcwd = _wgetdcwd(drive, 0, 0);
|
||||
if (!pcwd)
|
||||
|
@ -44,6 +44,7 @@ var LocalFile = CC("@mozilla.org/file/local;1", "nsILocalFile", "initWithPath");
|
||||
function run_test()
|
||||
{
|
||||
test_toplevel_parent_is_null();
|
||||
test_normalize_crash_if_media_missing();
|
||||
}
|
||||
|
||||
function test_toplevel_parent_is_null()
|
||||
@ -64,3 +65,20 @@ function test_toplevel_parent_is_null()
|
||||
do_check_eq(e.result, Cr.NS_ERROR_FILE_UNRECOGNIZED_PATH);
|
||||
}
|
||||
}
|
||||
|
||||
function test_normalize_crash_if_media_missing()
|
||||
{
|
||||
const a="a".charCodeAt(0);
|
||||
const z="z".charCodeAt(0);
|
||||
for (i = a; i <= z; ++i)
|
||||
{
|
||||
try
|
||||
{
|
||||
LocalFile(String.fromCharCode(i)+":.\\test").normalize();
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user