Changeset 244917 in webkit
- Timestamp:
- May 3, 2019 12:42:53 PM (5 years ago)
- Location:
- trunk/Source/WebKit
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r244916 r244917 1 2019-05-03 Brent Fulgham <bfulgham@apple.com> 2 3 Use more efficient path resolution logic 4 https://bugs.webkit.org/show_bug.cgi?id=197389 5 <rdar://problem/50268491> 6 7 Reviewed by Maciej Stachowiak. 8 9 The code in SandboxExtensionsCocoa.mm 'resolveSymlinksInPath' is pretty inefficient, and tries to reproduce (badly) 10 logic that is already provided by the operating system. 11 12 To make matters worse, 'resolvePathForSandboxExtension' was effectively performing the work of fully resolving 13 symlinks twice, since NSString's 'stringByStandardizingPath' method does some of this already. 14 15 Instead, we should just use NSString's 'stringByResolvingSymlinksInPath', which does the symlink resolution 16 using more efficient logic than our 'resolveSymlinksInPath' code. 17 18 * Shared/Cocoa/SandboxExtensionCocoa.mm: 19 (WebKit::resolveSymlinksInPath): Removed. 20 (WebKit::resolvePathForSandboxExtension): Remove redundant call to 'resolveSymlinksInPath', and switches from 21 'stringByStandardizingPath' to 'stringByResolvingSymlinksInPath', which can take the place of both calls. 22 (WebKit::stringByResolvingSymlinksInPath): Switch to call 'stringByResolvingSymlinksInPath'. 23 1 24 2019-05-02 Dean Jackson <dino@apple.com> 2 25 -
trunk/Source/WebKit/Shared/Cocoa/SandboxExtensionCocoa.mm
r244747 r244917 1 1 /* 2 * Copyright (C) 2010-201 6Apple Inc. All rights reserved.2 * Copyright (C) 2010-2019 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 32 32 #import "Decoder.h" 33 33 #import "Encoder.h" 34 #import <sys/stat.h>35 34 #import <wtf/FileSystem.h> 36 35 #import <wtf/spi/darwin/SandboxSPI.h> … … 226 225 } 227 226 228 static CString resolveSymlinksInPath(const CString& path)229 {230 struct stat statBuf;231 232 // Check if this file exists.233 if (!stat(path.data(), &statBuf)) {234 char resolvedName[PATH_MAX];235 236 return realpath(path.data(), resolvedName);237 }238 239 const char* slashPtr = strrchr(path.data(), '/');240 if (slashPtr == path.data())241 return path;242 243 size_t parentDirectoryLength = slashPtr - path.data();244 if (parentDirectoryLength >= PATH_MAX)245 return CString();246 247 // Get the parent directory.248 char parentDirectory[PATH_MAX];249 memcpy(parentDirectory, path.data(), parentDirectoryLength);250 parentDirectory[parentDirectoryLength] = '\0';251 252 // Resolve it.253 CString resolvedParentDirectory = resolveSymlinksInPath(CString(parentDirectory));254 if (resolvedParentDirectory.isNull())255 return CString();256 257 size_t lastPathComponentLength = path.length() - parentDirectoryLength;258 size_t resolvedPathLength = resolvedParentDirectory.length() + lastPathComponentLength;259 if (resolvedPathLength >= PATH_MAX)260 return CString();261 262 // Combine the resolved parent directory with the last path component.263 char* resolvedPathBuffer;264 CString resolvedPath = CString::newUninitialized(resolvedPathLength, resolvedPathBuffer);265 memcpy(resolvedPathBuffer, resolvedParentDirectory.data(), resolvedParentDirectory.length());266 memcpy(resolvedPathBuffer + resolvedParentDirectory.length(), slashPtr, lastPathComponentLength);267 268 return resolvedPath;269 }270 271 227 String stringByResolvingSymlinksInPath(const String& path) 272 228 { 273 return String::fromUTF8(resolveSymlinksInPath(path.utf8()));229 return [(NSString *)path stringByResolvingSymlinksInPath]; 274 230 } 275 231 … … 289 245 String resolvePathForSandboxExtension(const String& path) 290 246 { 291 // FIXME: Do we need both resolveSymlinksInPath() and -stringByStandardizingPath? 292 CString fileSystemPath = FileSystem::fileSystemRepresentation([(NSString *)path stringByStandardizingPath]); 293 if (fileSystemPath.isNull()) { 294 LOG_ERROR("Could not create a valid file system representation for the string '%s' of length %lu", fileSystemPath.data(), fileSystemPath.length()); 247 String resolvedPath = stringByResolvingSymlinksInPath(path); 248 if (resolvedPath.isEmpty()) { 249 LOG_ERROR("Could not create a valid file system representation for the string '%s' of length %lu", resolvedPath.utf8().data(), resolvedPath.length()); 295 250 return { }; 296 251 } 297 252 298 CString standardizedPath = resolveSymlinksInPath(fileSystemPath); 299 return String::fromUTF8(standardizedPath); 253 return resolvedPath; 300 254 } 301 255
Note: See TracChangeset
for help on using the changeset viewer.