relocate path assertion definitions for more appropriate organisation
This commit is contained in:
40
palps.rkt
40
palps.rkt
@@ -9,6 +9,26 @@
|
||||
;; directory of the current user of the program
|
||||
(define call-dir (make-parameter (string->path "/nobody")))
|
||||
|
||||
;; raised by assert-confined-to-call-dir when attemping to traverse
|
||||
;; outside of (call-dir)
|
||||
(struct exn:fail:contract:illegal-path exn:fail:contract ()
|
||||
#:extra-constructor-name make-exn:fail:contract:illegal-path
|
||||
#:transparent)
|
||||
|
||||
;; check if path, once resolved, is a child of base
|
||||
(define (confined-path? base path)
|
||||
(string-prefix?
|
||||
(path->string (simplify-path (build-path base path)))
|
||||
(path->string (simplify-path base))))
|
||||
|
||||
;; asserts that path is within (call-dir), and raises
|
||||
;; exn:fail:contract:illegal-path otherwise.
|
||||
(define (assert-confined-to-call-dir path)
|
||||
(when (not (confined-path? (call-dir) path))
|
||||
(raise (make-exn:fail:contract:illegal-path
|
||||
"assert-confined-to-call-dir: traversed outside of root"
|
||||
(current-continuation-marks)))))
|
||||
|
||||
(define (call-valid? call)
|
||||
(and
|
||||
(<= (string-length call) 9)
|
||||
@@ -75,26 +95,6 @@
|
||||
path])))
|
||||
(loop))
|
||||
|
||||
;; raised by assert-confined-to-call-dir when attemping to traverse
|
||||
;; outside of (call-dir)
|
||||
(struct exn:fail:contract:illegal-path exn:fail:contract ()
|
||||
#:extra-constructor-name make-exn:fail:contract:illegal-path
|
||||
#:transparent)
|
||||
|
||||
;; check if path, once resolved, is a child of base
|
||||
(define (confined-path? base path)
|
||||
(string-prefix?
|
||||
(path->string (simplify-path (build-path base path)))
|
||||
(path->string (simplify-path base))))
|
||||
|
||||
;; asserts that path is within (call-dir), and raises
|
||||
;; exn:fail:contract:illegal-path otherwise.
|
||||
(define (assert-confined-to-call-dir path)
|
||||
(when (not (confined-path? (call-dir) path))
|
||||
(raise (make-exn:fail:contract:illegal-path
|
||||
"assert-confined-to-call-dir: traversed outside of root"
|
||||
(current-continuation-marks)))))
|
||||
|
||||
;; "main" procedure to be executed in an interactive context i.e. for
|
||||
;; BPQ
|
||||
(define (session-startup)
|
||||
|
||||
Reference in New Issue
Block a user