blob: 61c6966b02c9feb9c6a0c52ebef0f287a02afaf5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
[windows] skip 'filesystem normalizes / to \'
[plan9] skip 'filesystem disallows \n in paths'
# If the directory path containing a package to be built includes a newline,
# the go command should refuse to even try to build the package.
env DIR=$WORK${/}${newline}'package main'${newline}'func main() { panic("uh-oh")'${newline}'/*'
mkdir $DIR
cd $DIR
exec pwd
cp $WORK/go.mod ./go.mod
cp $WORK/main.go ./main.go
cp $WORK/main_test.go ./main_test.go
! go build -o $devnull .
stderr 'package example: invalid package directory .*uh-oh'
! go build -o $devnull main.go
stderr 'package command-line-arguments: invalid package directory .*uh-oh'
! go run .
stderr 'package example: invalid package directory .*uh-oh'
! go run main.go
stderr 'package command-line-arguments: invalid package directory .*uh-oh'
! go test .
stderr 'package example: invalid package directory .*uh-oh'
! go test -v main.go main_test.go
stderr 'package command-line-arguments: invalid package directory .*uh-oh'
# Since we do preserve $PWD (or set it appropriately) for commands, and we do
# not resolve symlinks unnecessarily, referring to the contents of the unsafe
# directory via a safe symlink should be ok, and should not inject the data from
# the symlink target path.
[!symlink] stop 'remainder of test checks symlink behavior'
[short] stop 'links and runs binaries'
symlink $WORK${/}link -> $DIR
go run $WORK${/}link${/}main.go
! stdout panic
! stderr panic
stderr '^ok$'
go test -v $WORK${/}link${/}main.go $WORK${/}link${/}main_test.go
! stdout panic
! stderr panic
stdout '^ok$' # 'go test' combines the test's stdout into stderr
cd $WORK/link
! go run $DIR${/}main.go
stderr 'package command-line-arguments: invalid package directory .*uh-oh'
go run .
! stdout panic
! stderr panic
stderr '^ok$'
go run main.go
! stdout panic
! stderr panic
stderr '^ok$'
go test -v
! stdout panic
! stderr panic
stdout '^ok$' # 'go test' combines the test's stdout into stderr
go test -v .
! stdout panic
! stderr panic
stdout '^ok$' # 'go test' combines the test's stdout into stderr
-- $WORK/go.mod --
module example
go 1.19
-- $WORK/main.go --
package main
import "C"
func main() {
/* nothing here */
println("ok")
}
-- $WORK/main_test.go --
package main
import "testing"
func TestMain(*testing.M) {
main()
}
|