WebKit Bugzilla
Attachment 368961 Details for
Bug 197389
: Use more efficient path resolution logic in SandboxExtensions
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch for landing
bug-197389-20190503120419.patch (text/plain), 5.43 KB, created by
Brent Fulgham
on 2019-05-03 12:04:19 PDT
(
hide
)
Description:
Patch for landing
Filename:
MIME Type:
Creator:
Brent Fulgham
Created:
2019-05-03 12:04:19 PDT
Size:
5.43 KB
patch
obsolete
>Subversion Revision: 244915 >diff --git a/Source/WebKit/ChangeLog b/Source/WebKit/ChangeLog >index e75a01270b265192411e15f589a1ec28c224adc8..a9cad05e2cc027ab2d0054aecd2c6929723eeade 100644 >--- a/Source/WebKit/ChangeLog >+++ b/Source/WebKit/ChangeLog >@@ -1,3 +1,26 @@ >+2019-05-03 Brent Fulgham <bfulgham@apple.com> >+ >+ Use more efficient path resolution logic >+ https://bugs.webkit.org/show_bug.cgi?id=197389 >+ <rdar://problem/50268491> >+ >+ Reviewed by Maciej Stachowiak. >+ >+ The code in SandboxExtensionsCocoa.mm 'resolveSymlinksInPath' is pretty inefficient, and tries to reproduce (badly) >+ logic that is already provided by the operating system. >+ >+ To make matters worse, 'resolvePathForSandboxExtension' was effectively performing the work of fully resolving >+ symlinks twice, since NSString's 'stringByStandardizingPath' method does some of this already. >+ >+ Instead, we should just use NSString's 'stringByResolvingSymlinksInPath', which does the symlink resolution >+ using more efficient logic than our 'resolveSymlinksInPath' code. >+ >+ * Shared/Cocoa/SandboxExtensionCocoa.mm: >+ (WebKit::resolveSymlinksInPath): Removed. >+ (WebKit::resolvePathForSandboxExtension): Remove redundant call to 'resolveSymlinksInPath', and switches from >+ 'stringByStandardizingPath' to 'stringByResolvingSymlinksInPath', which can take the place of both calls. >+ (WebKit::stringByResolvingSymlinksInPath): Switch to call 'stringByResolvingSymlinksInPath'. >+ > 2019-05-02 Dean Jackson <dino@apple.com> > > Provide UIImages for element actions >diff --git a/Source/WebKit/Shared/Cocoa/SandboxExtensionCocoa.mm b/Source/WebKit/Shared/Cocoa/SandboxExtensionCocoa.mm >index c2ec473e9b0d28bb731c71136d8bf416ee4485db..3bb25e71673e8dd8bc7f1ea1ad3b3bb3963021da 100644 >--- a/Source/WebKit/Shared/Cocoa/SandboxExtensionCocoa.mm >+++ b/Source/WebKit/Shared/Cocoa/SandboxExtensionCocoa.mm >@@ -1,5 +1,5 @@ > /* >- * Copyright (C) 2010-2016 Apple Inc. All rights reserved. >+ * Copyright (C) 2010-2019 Apple Inc. All rights reserved. > * > * Redistribution and use in source and binary forms, with or without > * modification, are permitted provided that the following conditions >@@ -31,7 +31,6 @@ > #import "DataReference.h" > #import "Decoder.h" > #import "Encoder.h" >-#import <sys/stat.h> > #import <wtf/FileSystem.h> > #import <wtf/spi/darwin/SandboxSPI.h> > #import <wtf/text/CString.h> >@@ -225,52 +224,9 @@ RefPtr<SandboxExtension> SandboxExtension::create(Handle&& handle) > return adoptRef(new SandboxExtension(handle)); > } > >-static CString resolveSymlinksInPath(const CString& path) >-{ >- struct stat statBuf; >- >- // Check if this file exists. >- if (!stat(path.data(), &statBuf)) { >- char resolvedName[PATH_MAX]; >- >- return realpath(path.data(), resolvedName); >- } >- >- const char* slashPtr = strrchr(path.data(), '/'); >- if (slashPtr == path.data()) >- return path; >- >- size_t parentDirectoryLength = slashPtr - path.data(); >- if (parentDirectoryLength >= PATH_MAX) >- return CString(); >- >- // Get the parent directory. >- char parentDirectory[PATH_MAX]; >- memcpy(parentDirectory, path.data(), parentDirectoryLength); >- parentDirectory[parentDirectoryLength] = '\0'; >- >- // Resolve it. >- CString resolvedParentDirectory = resolveSymlinksInPath(CString(parentDirectory)); >- if (resolvedParentDirectory.isNull()) >- return CString(); >- >- size_t lastPathComponentLength = path.length() - parentDirectoryLength; >- size_t resolvedPathLength = resolvedParentDirectory.length() + lastPathComponentLength; >- if (resolvedPathLength >= PATH_MAX) >- return CString(); >- >- // Combine the resolved parent directory with the last path component. >- char* resolvedPathBuffer; >- CString resolvedPath = CString::newUninitialized(resolvedPathLength, resolvedPathBuffer); >- memcpy(resolvedPathBuffer, resolvedParentDirectory.data(), resolvedParentDirectory.length()); >- memcpy(resolvedPathBuffer + resolvedParentDirectory.length(), slashPtr, lastPathComponentLength); >- >- return resolvedPath; >-} >- > String stringByResolvingSymlinksInPath(const String& path) > { >- return String::fromUTF8(resolveSymlinksInPath(path.utf8())); >+ return [(NSString *)path stringByResolvingSymlinksInPath]; > } > > String resolveAndCreateReadWriteDirectoryForSandboxExtension(const String& path) >@@ -288,15 +244,13 @@ String resolveAndCreateReadWriteDirectoryForSandboxExtension(const String& path) > > String resolvePathForSandboxExtension(const String& path) > { >- // FIXME: Do we need both resolveSymlinksInPath() and -stringByStandardizingPath? >- CString fileSystemPath = FileSystem::fileSystemRepresentation([(NSString *)path stringByStandardizingPath]); >- if (fileSystemPath.isNull()) { >- LOG_ERROR("Could not create a valid file system representation for the string '%s' of length %lu", fileSystemPath.data(), fileSystemPath.length()); >+ String resolvedPath = stringByResolvingSymlinksInPath(path); >+ if (resolvedPath.isEmpty()) { >+ LOG_ERROR("Could not create a valid file system representation for the string '%s' of length %lu", resolvedPath.utf8().data(), resolvedPath.length()); > return { }; > } > >- CString standardizedPath = resolveSymlinksInPath(fileSystemPath); >- return String::fromUTF8(standardizedPath); >+ return resolvedPath; > } > > bool SandboxExtension::createHandleWithoutResolvingPath(const String& path, Type type, Handle& handle)
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 197389
:
368496
|
368512
|
368519
|
368624
|
368806
|
368872
|
368961
|
369156