Skip to content

Commit

Permalink
Better safeguards in File.resolveTilde
Browse files Browse the repository at this point in the history
Former-commit-id: 2552d79
  • Loading branch information
kjessup committed Nov 28, 2016
1 parent b8aec42 commit 831b724
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Sources/PerfectLib/File.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,14 @@ public class File {
static func resolveTilde(inPath: String) -> String {
if !inPath.isEmpty && inPath[inPath.startIndex] == "~" {
var wexp = wordexp_t()
wordexp(inPath, &wexp, 0)
if let resolved = wexp.we_wordv[0], let pth = String(validatingUTF8: resolved) {
guard 0 == wordexp(inPath, &wexp, 0),
let we_wordv = wexp.we_wordv else {
return inPath
}
defer {
wordfree(&wexp)
}
if let resolved = we_wordv[0], let pth = String(validatingUTF8: resolved) {
return pth
}
}
Expand Down

0 comments on commit 831b724

Please sign in to comment.