[SCM] WebKit Debian packaging branch, debian/unstable, updated. debian/1.1.15-1-40151-g37bb677

trey trey at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 07:19:00 UTC 2009


The following commit has been merged in the debian/unstable branch:
commit 66177e0b384dc8dc5d5731ee1f2341c30dae849f
Author: trey <trey at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Thu Jan 9 07:50:51 2003 +0000

    	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

diff --git a/WebKit/ChangeLog b/WebKit/ChangeLog
index b6b6414..f25bb90 100644
--- a/WebKit/ChangeLog
+++ b/WebKit/ChangeLog
@@ -1,3 +1,23 @@
+2003-01-08  Trey Matteson  <trey at 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 at apple.com>
 
 	Fixed: 3111432 - Support OBJECT tags with type text/plain or text/html
diff --git a/WebKit/Downloads.subproj/WebDownload.m b/WebKit/Downloads.subproj/WebDownload.m
index 992a481..6eadc05 100644
--- a/WebKit/Downloads.subproj/WebDownload.m
+++ b/WebKit/Downloads.subproj/WebDownload.m
@@ -133,13 +133,28 @@
 
 - (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 @@
 
         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;
             }
diff --git a/WebKit/Downloads.subproj/WebDownloadHandler.m b/WebKit/Downloads.subproj/WebDownloadHandler.m
index 992a481..6eadc05 100644
--- a/WebKit/Downloads.subproj/WebDownloadHandler.m
+++ b/WebKit/Downloads.subproj/WebDownloadHandler.m
@@ -133,13 +133,28 @@
 
 - (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 @@
 
         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;
             }
diff --git a/WebKit/WebView.subproj/WebMainResourceClient.m b/WebKit/WebView.subproj/WebMainResourceClient.m
index 2fbc81e..7ce09fd 100644
--- a/WebKit/WebView.subproj/WebMainResourceClient.m
+++ b/WebKit/WebView.subproj/WebMainResourceClient.m
@@ -197,7 +197,9 @@
                 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];
 	}
diff --git a/WebKit/WebView.subproj/WebMainResourceLoader.m b/WebKit/WebView.subproj/WebMainResourceLoader.m
index 2fbc81e..7ce09fd 100644
--- a/WebKit/WebView.subproj/WebMainResourceLoader.m
+++ b/WebKit/WebView.subproj/WebMainResourceLoader.m
@@ -197,7 +197,9 @@
                 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];
 	}

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list