Skip to content

Commit c3945e0

Browse files
committed
Avoid invalid memory reference when 1st arg of path-build is ""
1 parent 37a5a1f commit c3945e0

File tree

8 files changed

+30
-11
lines changed

8 files changed

+30
-11
lines changed

csug/io.stex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3887,6 +3887,7 @@ The preferred directory separator is \scheme{#\\} for Windows and
38873887

38883888
Combines \var{dir-path} and \var{path}, adding a directory separator
38893889
between them if needed.
3890+
If \var{dir-path} is the empty string, \var{path} is returned.
38903891

38913892
%----------------------------------------------------------------------------
38923893
\entryheader

mats/6.ms

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3332,6 +3332,7 @@
33323332
(error? (path-last 'a/b/c))
33333333
(error? (path-root 'a/b/c))
33343334
(error? (path-extension 'a/b/c))
3335+
(error? (path-build 'a 'b))
33353336

33363337
(eq? (path-absolute? "") #f)
33373338
(eq? (path-absolute? "a") #f)
@@ -3409,6 +3410,20 @@
34093410
(equal? (path-extension "c:..") "")
34103411
(equal? (path-extension "c:") "")
34113412

3413+
(equal? (path-build "" "b.ss") "b.ss")
3414+
(if (windows?)
3415+
(equal? (path-build "." "b.ss") ".\\b.ss")
3416+
(equal? (path-build "." "b.ss") "./b.ss"))
3417+
(if (windows?)
3418+
(equal? (path-build ".\\" "b.ss") ".\\b.ss")
3419+
(equal? (path-build "./" "b.ss") "./b.ss"))
3420+
(if (windows?)
3421+
(equal? (path-build "foo" "b.ss") "foo\\b.ss")
3422+
(equal? (path-build "foo" "b.ss") "foo/b.ss"))
3423+
(if (windows?)
3424+
(equal? (path-build "quux\\" "b.ss") "quux\\b.ss")
3425+
(equal? (path-build "quux/" "b.ss") "quux/b.ss"))
3426+
34123427
; if this test fails, search for the asterisks in the printed table
34133428
(let ([okay? #t])
34143429
(define print-table

mats/root-experr-compile-0-f-f-f

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7257,6 +7257,7 @@ cp0.mo:Expected error in mat expand/optimize-output: "expand/optimize-output: #<
72577257
6.mo:Expected error in mat pathprocs: "path-last: a/b/c is not a string".
72587258
6.mo:Expected error in mat pathprocs: "path-root: a/b/c is not a string".
72597259
6.mo:Expected error in mat pathprocs: "path-extension: a/b/c is not a string".
7260+
6.mo:Expected error in mat pathprocs: "path-build: a is not a string".
72607261
6.mo:Expected error in mat process: "write-char: not permitted on closed port sanitized-port".
72617262
6.mo:Expected error in mat process: "write-char: not permitted on closed port sanitized-port".
72627263
6.mo:Expected error in mat process: "flush-output-port: not permitted on closed port sanitized-port".

s/6.ss

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -544,12 +544,12 @@
544544
(lambda (dir fn)
545545
(unless (string? dir) ($oops who "~s is not a string" dir))
546546
(unless (string? fn) ($oops who "~s is not a string" fn))
547-
(format
548-
(if (directory-separator?
549-
(string-ref dir
550-
(fx- (string-length dir) 1)))
551-
"~a~a"
552-
(string-append "~a" (string (directory-separator)) "~a"))
553-
dir fn)))
547+
(cond
548+
[(string=? dir "") fn]
549+
[(directory-separator?
550+
(string-ref dir
551+
(fx- (string-length dir) 1)))
552+
(string-append dir fn)]
553+
[else (string-append dir (string (directory-separator)) fn)])))
554554
)
555555
)

s/7.ss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
(if (null? ls)
113113
($oops whoarg "file ~s not found in source directories" fn)
114114
(let ([path (let ([dir (car ls)])
115-
(if (or (string=? dir "") (string=? dir "."))
115+
(if (string=? dir ".")
116116
fn
117117
(path-build dir fn)))])
118118
(if (guard (c [#t #f]) (close-input-port (open-input-file path)) #t)

s/read.ss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1731,7 +1731,7 @@
17311731
(and (not (null? dir*))
17321732
(or (source-port
17331733
(let ([dir (car dir*)])
1734-
(if (or (string=? dir "") (string=? dir "."))
1734+
(if (string=? dir ".")
17351735
name
17361736
(path-build dir name))))
17371737
(search name (cdr dir*)))))

s/reboot.ss

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,9 @@
145145
[else
146146
(define path-build
147147
(lambda (a b)
148-
(let ([sep (if (eqv? (string-ref a (sub1 (string-length a))) #\/) "" "/")])
148+
(let ([sep (if (or (string=? a "")
149+
(eqv? (string-ref a (sub1 (string-length a)))) #\/)
150+
"" "/")])
149151
(string-append a sep b))))])
150152

151153
(let ([machine.def (path-build xc-dir "machine.def")])

s/syntax.ss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4787,7 +4787,7 @@
47874787
e1 e2 ...)]))
47884788
(define make-path
47894789
(lambda (dir rpath ext)
4790-
(if (or (string=? dir "") (string=? dir "."))
4790+
(if (string=? dir ".")
47914791
(format "~a~a" rpath ext)
47924792
(path-build dir (format "~a~a" rpath ext)))))
47934793
(let ([rpath (fold-left (lambda (dir elem) (path-build dir (symbol->string elem))) (symbol->string (car path)) (cdr path))])

0 commit comments

Comments
 (0)