Skip to content

Commit 7748c49

Browse files
aykevldeadprogram
authored andcommitted
compileopts: fix race condition
Appending to a slice can lead to a race condition if the capacity of the slice is larger than the length (and therefore the returned slice will overwrite some fields in the underlying array). This fixes that race condition. I don't know how severe this particular one is. It shouldn't be that severe, but it is a bug and it makes it easier to hunt for possibly more serious race conditions.
1 parent 50f700d commit 7748c49

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

compileopts/config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ func (c *Config) GOARM() string {
7474

7575
// BuildTags returns the complete list of build tags used during this build.
7676
func (c *Config) BuildTags() []string {
77-
tags := append(c.Target.BuildTags, []string{
77+
tags := append([]string(nil), c.Target.BuildTags...) // copy slice (avoid a race)
78+
tags = append(tags, []string{
7879
"tinygo", // that's the compiler
7980
"purego", // to get various crypto packages to work
8081
"math_big_pure_go", // to get math/big to work

0 commit comments

Comments
 (0)