Re: NSString, stringByAppendingPathComponent, and Canonicalization
Re: NSString, stringByAppendingPathComponent, and Canonicalization
- Subject: Re: NSString, stringByAppendingPathComponent, and Canonicalization
- From: Ken Thomases <email@hidden>
- Date: Mon, 04 Apr 2011 22:22:39 -0500
On Apr 4, 2011, at 10:08 PM, Jeffrey Walton wrote:
> I need to accept a filename from the user. Given the user supplied
> filename, I form a fully qualified name:
>
> NSString* pathName = [NSHomeDirectory(),
> stringByAppendingPathComponent:@"Documents"];
> NSString* fullPathName = [pathName stringByAppendingPathComponent:filename];
>
> How do I canonicalize the the resulting fullPathName to verify there
> was no directory traversal goodness in the filename?
NSString* fullPathName = [pathName stringByAppendingPathComponent:[filename lastPathComponent]];
Cheers,
Ken
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden