Skip to content

Commit

Permalink
Check injecting file is readable. (#203)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnno1962 committed Feb 18, 2020
1 parent e497fef commit 13f21d0
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions InjectionBundle/SwiftEval.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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("' ")
Expand Down

0 comments on commit 13f21d0

Please sign in to comment.