1
0

tufted: more robust merge-pathname impl

This commit is contained in:
Daniel Barlow 2024-12-17 17:24:40 +00:00
parent 464d046b5a
commit 2e5a8a572e

View File

@ -16,10 +16,18 @@
(print (.. "TFTP serving from " options.base-directory))
(fn merge-pathname [directory filename]
(if (directory:match "/$")
(.. directory filename)
(.. directory "/" filename)))
;; this is a copy of anoia append-path
(fn merge-pathname [dirname filename]
(let [base (or (string.match dirname "(.*)/$") dirname)
result []]
(each [component (string.gmatch filename "([^/]+)")]
(if (and (= component "..") (> (# result) 0))
(table.remove result)
(= component "..")
(error "path traversal attempt")
true
(table.insert result component)))
(.. base "/" (table.concat result "/"))))
(->
(tftp:listen