From 13f21d070042acfb0ac4bc1df99e675ac9f57ad1 Mon Sep 17 00:00:00 2001 From: John Holdsworth Date: Tue, 18 Feb 2020 12:40:53 +0100 Subject: [PATCH] Check injecting file is readable. (#203) --- InjectionBundle/SwiftEval.swift | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/InjectionBundle/SwiftEval.swift b/InjectionBundle/SwiftEval.swift index 6da5f3e8..a9c7c95f 100644 --- a/InjectionBundle/SwiftEval.swift +++ b/InjectionBundle/SwiftEval.swift @@ -433,6 +433,15 @@ public class SwiftEval: NSObject { // Objective-C paths can only contain space and ' // project file itself can only contain spaces let isFile = classNameOrFile.hasPrefix("/") + if isFile && (try? String(contentsOfFile: classNameOrFile)) == nil { + throw evalError(""" + File \(classNameOrFile) is not readable. This could be because + the file is in a secure area of the file system or because the + case of the letters in the file name does not match that in the + Xcode project. The file system injection uses is case sensitive. + """) + } + let sourceRegex = isFile ? "\\Q\(classNameOrFile)\\E" : "/\(classNameOrFile)\\.(?:swift|mm?)" let swiftEscaped = (isFile ? "" : "[^\"]*?") + sourceRegex.escaping("'$", with: "\\E\\\\*$0\\Q") let objcEscaped = (isFile ? "" : "\\S*?") + sourceRegex.escaping("' ")