Changeset 49273

Show
Ignore:
Timestamp:
10/07/09 16:20:31 (5 months ago)
Author:
darin@apple.com
Message:

Make the setMetadataURL function foolproof by having it remove user info
 https://bugs.webkit.org/show_bug.cgi?id=30178
 rdar://problem/6544670

Patch by Darin Adler < darin@apple.com> on 2009-10-07
Reviewed by John Sullivan.

* Misc/WebNSFileManagerExtras.m:
(-[NSFileManager _webkit_setMetadataURL:referrer:atPath:]):
Call _web_URLByRemovingUserInfo on the passed in URL string after converting
it to a URL, and then convert it back to a string.

* Misc/WebNSURLExtras.h: Added _web_URLByRemovingUserInfo.
* Misc/WebNSURLExtras.mm: Removed unused WebKitURLComponents struct.
(-[NSURL _web_URLByTruncatingOneCharacterBeforeComponent:]): Renamed to be
clearer on what this does.
(-[NSURL _webkit_URLByRemovingFragment]): Changed to call new name.
(-[NSURL _webkit_URLByRemovingResourceSpecifier]): Ditto.
(-[NSURL _web_URLByRemovingComponentAndSubsequentCharacter:]): Added.
(-[NSURL _web_URLByRemovingUserInfo]): Added.

Location:
trunk/WebKit/mac
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/WebKit/mac/ChangeLog

    r49271 r49273  
     12009-10-07  Darin Adler  <darin@apple.com> 
     2 
     3        Reviewed by John Sullivan. 
     4 
     5        Make the setMetadataURL function foolproof by having it remove user info 
     6        https://bugs.webkit.org/show_bug.cgi?id=30178 
     7        rdar://problem/6544670 
     8 
     9        * Misc/WebNSFileManagerExtras.m: 
     10        (-[NSFileManager _webkit_setMetadataURL:referrer:atPath:]): 
     11        Call _web_URLByRemovingUserInfo on the passed in URL string after converting 
     12        it to a URL, and then convert it back to a string. 
     13 
     14        * Misc/WebNSURLExtras.h: Added _web_URLByRemovingUserInfo. 
     15        * Misc/WebNSURLExtras.mm: Removed unused WebKitURLComponents struct. 
     16        (-[NSURL _web_URLByTruncatingOneCharacterBeforeComponent:]): Renamed to be 
     17        clearer on what this does. 
     18        (-[NSURL _webkit_URLByRemovingFragment]): Changed to call new name. 
     19        (-[NSURL _webkit_URLByRemovingResourceSpecifier]): Ditto. 
     20        (-[NSURL _web_URLByRemovingComponentAndSubsequentCharacter:]): Added. 
     21        (-[NSURL _web_URLByRemovingUserInfo]): Added. 
     22 
    1232009-10-07  Simon Fraser  <simon.fraser@apple.com> 
    224 
  • trunk/WebKit/mac/Misc/WebNSFileManagerExtras.m

    r44255 r49273  
    11/* 
    2  * Copyright (C) 2005 Apple Computer, Inc. All rights reserved. 
     2 * Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. 
    33 * 
    44 * Redistribution and use in source and binary forms, with or without 
     
    2929#import <WebKit/WebNSFileManagerExtras.h> 
    3030 
     31#import "WebKitNSStringExtras.h" 
     32#import "WebNSURLExtras.h" 
    3133#import <WebCore/FoundationExtras.h> 
    32 #import <WebKit/WebKitNSStringExtras.h> 
    3334#import <WebKitSystemInterface.h> 
    34 #import <wtf/Assertions.h> 
    35  
    3635#import <pthread.h> 
    3736#import <sys/mount.h> 
     37#import <JavaScriptCore/Assertions.h> 
    3838 
    3939@implementation NSFileManager (WebNSFileManagerExtras) 
     
    171171    ASSERT(URLString); 
    172172    ASSERT(path); 
     173 
     174    NSURL *URL = [NSURL _web_URLWithUserTypedString:URLString]; 
     175    if (URL) 
     176        URLString = [[URL _web_URLByRemovingUserInfo] _web_userVisibleString]; 
    173177  
    174178    // Spawn a background thread for WKSetMetadataURL because this function will not return until mds has 
  • trunk/WebKit/mac/Misc/WebNSURLExtras.h

    r40346 r49273  
    11/* 
    2  * Copyright (C) 2005 Apple Computer, Inc. All rights reserved. 
     2 * Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. 
    33 * 
    44 * Redistribution and use in source and binary forms, with or without 
     
    2929#import <Foundation/Foundation.h> 
    3030 
     31// FIXME: Change method names back to _web_ from _webkit_ when identically-named 
     32// methods are no longer present in Foundation. 
     33 
    3134@interface NSURL (WebNSURLExtras) 
    3235 
     
    5356- (BOOL)_web_isEmpty; 
    5457 
    55 // FIXME: change these names back to _web_ when identically-named 
    56 // methods are removed from Foundation 
    57  
    5858- (NSURL *)_webkit_canonicalize; 
    5959- (NSURL *)_webkit_URLByRemovingFragment; 
    6060- (NSURL *)_webkit_URLByRemovingResourceSpecifier; 
     61- (NSURL *)_web_URLByRemovingUserInfo; 
    6162 
    6263- (BOOL)_webkit_isJavaScriptURL; 
     
    8485- (NSString *)_web_encodeHostName; // turns Unicode into funny-looking ASCII form, returns self if no decoding needed, convenient cover 
    8586 
    86 // FIXME: change these names back to _web_ when identically-named 
    87 // methods are removed from or renamed in Foundation 
    8887- (BOOL)_webkit_isJavaScriptURL; 
    8988- (BOOL)_webkit_isFTPDirectoryURL; 
  • trunk/WebKit/mac/Misc/WebNSURLExtras.mm

    r45254 r49273  
    11/* 
    2  * Copyright (C) 2005, 2007, 2008 Apple Inc. All rights reserved. 
     2 * Copyright (C) 2005, 2007, 2008, 2009 Apple Inc. All rights reserved. 
    33 * Copyright (C) 2006 Alexey Proskuryakov (ap@nypop.com) 
    44 * 
     
    620620} 
    621621 
    622 typedef struct { 
    623     NSString *scheme; 
    624     NSString *user; 
    625     NSString *password; 
    626     NSString *host; 
    627     CFIndex port; // kCFNotFound means ignore/omit 
    628     NSString *path; 
    629     NSString *query; 
    630     NSString *fragment; 
    631 } WebKitURLComponents; 
    632  
    633 - (NSURL *)_webkit_URLByRemovingComponent:(CFURLComponentType)component 
     622- (NSURL *)_web_URLByTruncatingOneCharacterBeforeComponent:(CFURLComponentType)component 
    634623{ 
    635624    CFRange fragRg = CFURLGetByteRangeForComponent((CFURLRef)self, component, NULL); 
    636     // Check to see if a fragment exists before decomposing the URL. 
    637625    if (fragRg.location == kCFNotFound) 
    638626        return self; 
     
    657645- (NSURL *)_webkit_URLByRemovingFragment 
    658646{ 
    659     return [self _webkit_URLByRemovingComponent:kCFURLComponentFragment]; 
     647    return [self _web_URLByTruncatingOneCharacterBeforeComponent:kCFURLComponentFragment]; 
    660648} 
    661649 
    662650- (NSURL *)_webkit_URLByRemovingResourceSpecifier 
    663651{ 
    664     return [self _webkit_URLByRemovingComponent:kCFURLComponentResourceSpecifier]; 
     652    return [self _web_URLByTruncatingOneCharacterBeforeComponent:kCFURLComponentResourceSpecifier]; 
     653} 
     654 
     655- (NSURL *)_web_URLByRemovingComponentAndSubsequentCharacter:(CFURLComponentType)component 
     656{ 
     657    CFRange range = CFURLGetByteRangeForComponent((CFURLRef)self, component, 0); 
     658    if (range.location == kCFNotFound) 
     659        return self; 
     660 
     661    // Remove one subsequent character. 
     662    ++range.length; 
     663 
     664    UInt8* urlBytes; 
     665    UInt8 buffer[2048]; 
     666    CFIndex numBytes = CFURLGetBytes((CFURLRef)self, buffer, 2048); 
     667    if (numBytes == -1) { 
     668        numBytes = CFURLGetBytes((CFURLRef)self, NULL, 0); 
     669        urlBytes = static_cast<UInt8*>(malloc(numBytes)); 
     670        CFURLGetBytes((CFURLRef)self, urlBytes, numBytes); 
     671    } else 
     672        urlBytes = buffer; 
     673 
     674    if (numBytes < range.location) 
     675        return self; 
     676    if (numBytes < range.location + range.length) 
     677        range.length = numBytes - range.location; 
     678 
     679    memmove(urlBytes + range.location, urlBytes + range.location + range.length, numBytes - range.location + range.length); 
     680 
     681    NSURL *result = (NSURL *)CFMakeCollectable(CFURLCreateWithBytes(NULL, urlBytes, numBytes - range.length, kCFStringEncodingUTF8, NULL)); 
     682    if (!result) 
     683        result = (NSURL *)CFMakeCollectable(CFURLCreateWithBytes(NULL, urlBytes, numBytes - range.length, kCFStringEncodingISOLatin1, NULL)); 
     684 
     685    if (urlBytes != buffer) 
     686        free(urlBytes); 
     687 
     688    return result ? [result autorelease] : self; 
     689} 
     690 
     691- (NSURL *)_web_URLByRemovingUserInfo 
     692{ 
     693    return [self _web_URLByRemovingComponentAndSubsequentCharacter:kCFURLComponentUserInfo]; 
    665694} 
    666695