cs: reject certain srclocs in marshaled form

This commit is contained in:
Matthew Flatt 2019-01-31 08:55:05 -07:00
parent cf72bace95
commit 8b4075bd3d
2 changed files with 20 additions and 8 deletions

View File

@ -51,13 +51,22 @@
(define p (if (path-for-srcloc? orig-p) (define p (if (path-for-srcloc? orig-p)
(path-for-srcloc-path orig-p) (path-for-srcloc-path orig-p)
orig-p)) orig-p))
(or (path->relative-path-elements p) (cond
(cond [(path? p)
[(path-for-srcloc? orig-p) (or (path->relative-path-elements p)
;; Can't make relative, so create a string that keeps up (cond
;; to two path elements [(path-for-srcloc? orig-p)
(truncate-path p)] ;; Can't make relative, so create a string that keeps up
[else (path->bytes p)])))) ;; to two path elements
(truncate-path p)]
[else (path->bytes p)]))]
[(or (string? p) (bytes? p) (symbol? p) (not p))
;; Allowed in compiled form
p]
[else
(error 'write
"cannot marshal value that is embedded in compiled code: ~V"
p)])))
(define (compiled-path->path e) (define (compiled-path->path e)
(cond (cond

View File

@ -174,7 +174,10 @@
[(srcloc? q) [(srcloc? q)
`(unsafe-make-srcloc `(unsafe-make-srcloc
,(let ([src (srcloc-source q)]) ,(let ([src (srcloc-source q)])
(if (and (path? src) (not for-cify?)) (if (and (not for-cify?)
;; Need to handle paths, need to reject (later) anything other
;; than a few type slike strings and byte strings
(not (or (string? src) (bytes? src) (symbol? src) (not src))))
;; Like paths, `path-for-srcloc` must be recognized later ;; Like paths, `path-for-srcloc` must be recognized later
(make-construct (path-for-srcloc src)) (make-construct (path-for-srcloc src))
(make-construct src))) (make-construct src)))