Commit 66177e0b authored by trey's avatar trey
Browse files

3142201 - home directory nuked during power download session

	We add checks for various error cases that could combine to cause this problem.  While we
	never got a reproducible case, we are confident that this is the only file removal done
	in the download code, and its ability to wreak havoc has been clipped.

        Reviewed by Richard.

        * Downloads.subproj/WebDownloadHandler.m:
        (-[WebDownloadHandler cleanUpAfterFailure]):  Only nuke the partial download if in fact we created
	a new download file.  Never nuke a directory.
        (-[WebDownloadHandler createFileIfNecessary]):  Don't add "." to the foo-1 filenames we generate
	if the original filename doesn't have any extension.
        * WebView.subproj/WebMainResourceClient.m:
        (-[WebMainResourceClient continueAfterContentPolicy:response:]):
	If the policyDelegate gives us a nil filename, just stop the whole load, instead of trying to
	overwrite the user's home directory.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@3281 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 5066da21
2003-01-08 Trey Matteson <trey@apple.com>
3142201 - home directory nuked during power download session
We add checks for various error cases that could combine to cause this problem. While we
never got a reproducible case, we are confident that this is the only file removal done
in the download code, and its ability to wreak havoc has been clipped.
Reviewed by Richard.
* Downloads.subproj/WebDownloadHandler.m:
(-[WebDownloadHandler cleanUpAfterFailure]): Only nuke the partial download if in fact we created
a new download file. Never nuke a directory.
(-[WebDownloadHandler createFileIfNecessary]): Don't add "." to the foo-1 filenames we generate
if the original filename doesn't have any extension.
* WebView.subproj/WebMainResourceClient.m:
(-[WebMainResourceClient continueAfterContentPolicy:response:]):
If the policyDelegate gives us a nil filename, just stop the whole load, instead of trying to
overwrite the user's home directory.
2003-01-08 Chris Blumenberg <cblu@apple.com>
Fixed: 3111432 - Support OBJECT tags with type text/plain or text/html
......
......@@ -133,13 +133,28 @@ - (void)closeFile
- (void)cleanUpAfterFailure
{
NSString *path = [dataSource downloadPath];
[self closeFile];
[[NSFileManager defaultManager] removeFileAtPath:path handler:nil];
[[NSWorkspace sharedWorkspace] _web_noteFileChangedAtPath:path];
if (fileRefPtr) {
// Only cleanup if we have opened a file, since the downloadPath might be an existing
// file that we haven't discovered that we conflict with
NSString *path = [dataSource downloadPath];
[self closeFile];
NSFileManager *fileMgr = [NSFileManager defaultManager];
BOOL isDirectory;
BOOL fileExists = [fileMgr fileExistsAtPath:path isDirectory:&isDirectory];
if (fileExists && !isDirectory) {
[fileMgr removeFileAtPath:path handler:nil];
[[NSWorkspace sharedWorkspace] _web_noteFileChangedAtPath:path];
} else if (!fileExists) {
ERROR("Download file disappeared in the middle of download");
} else {
// Note we currently don't support downloading directories, so we know this is wrong
ERROR("Download file is a directory - will not be removed");
}
} else {
ERROR("Was about to remove a non-download file");
}
}
- (WebError *)createFileIfNecessary
......@@ -166,7 +181,11 @@ - (WebError *)createFileIfNecessary
for (i = 1; 1; i++) {
pathWithAppendedNumber = [NSString stringWithFormat:@"%@-%d", pathWithoutExtension, i];
path = [pathWithAppendedNumber stringByAppendingPathExtension:extension];
if (extension && [extension length]) {
path = [pathWithAppendedNumber stringByAppendingPathExtension:extension];
} else {
path = pathWithAppendedNumber;
}
if (![fileManager fileExistsAtPath:path]) {
break;
}
......
......@@ -133,13 +133,28 @@ - (void)closeFile
- (void)cleanUpAfterFailure
{
NSString *path = [dataSource downloadPath];
[self closeFile];
[[NSFileManager defaultManager] removeFileAtPath:path handler:nil];
[[NSWorkspace sharedWorkspace] _web_noteFileChangedAtPath:path];
if (fileRefPtr) {
// Only cleanup if we have opened a file, since the downloadPath might be an existing
// file that we haven't discovered that we conflict with
NSString *path = [dataSource downloadPath];
[self closeFile];
NSFileManager *fileMgr = [NSFileManager defaultManager];
BOOL isDirectory;
BOOL fileExists = [fileMgr fileExistsAtPath:path isDirectory:&isDirectory];
if (fileExists && !isDirectory) {
[fileMgr removeFileAtPath:path handler:nil];
[[NSWorkspace sharedWorkspace] _web_noteFileChangedAtPath:path];
} else if (!fileExists) {
ERROR("Download file disappeared in the middle of download");
} else {
// Note we currently don't support downloading directories, so we know this is wrong
ERROR("Download file is a directory - will not be removed");
}
} else {
ERROR("Was about to remove a non-download file");
}
}
- (WebError *)createFileIfNecessary
......@@ -166,7 +181,11 @@ - (WebError *)createFileIfNecessary
for (i = 1; 1; i++) {
pathWithAppendedNumber = [NSString stringWithFormat:@"%@-%d", pathWithoutExtension, i];
path = [pathWithAppendedNumber stringByAppendingPathExtension:extension];
if (extension && [extension length]) {
path = [pathWithAppendedNumber stringByAppendingPathExtension:extension];
} else {
path = pathWithAppendedNumber;
}
if (![fileManager fileExistsAtPath:path]) {
break;
}
......
......@@ -197,7 +197,9 @@ -(void)continueAfterContentPolicy:(WebPolicyAction)contentPolicy response:(WebRe
saveFilenameForResponse:r andRequest:req];
// FIXME: Maybe there a cleaner way handle the bad filename case?
if(!saveFilename || [saveFilename length] == 0){
saveFilename = NSHomeDirectory();
ERROR("Nil or empty response to saveFilenameForResponse:andRequest:.");
[self stopLoadingForPolicyChange];
return;
}
[dataSource _setDownloadPath:saveFilename];
}
......
......@@ -197,7 +197,9 @@ -(void)continueAfterContentPolicy:(WebPolicyAction)contentPolicy response:(WebRe
saveFilenameForResponse:r andRequest:req];
// FIXME: Maybe there a cleaner way handle the bad filename case?
if(!saveFilename || [saveFilename length] == 0){
saveFilename = NSHomeDirectory();
ERROR("Nil or empty response to saveFilenameForResponse:andRequest:.");
[self stopLoadingForPolicyChange];
return;
}
[dataSource _setDownloadPath:saveFilename];
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment