aboutsummaryrefslogtreecommitdiffhomepage
path: root/compileopts
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2024-04-27 10:03:59 +0200
committerRon Evans <[email protected]>2024-04-27 11:12:19 +0200
commit7748c4922e426798ebb878eb48ba0d2d0dc0db09 (patch)
tree7b681a171212317e8a3f9205bdab7d1b3b3f9f48 /compileopts
parent50f700ddb58f4f920ddf3e377537ee545f26bb26 (diff)
downloadtinygo-7748c4922e426798ebb878eb48ba0d2d0dc0db09.tar.gz
tinygo-7748c4922e426798ebb878eb48ba0d2d0dc0db09.zip
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.
Diffstat (limited to 'compileopts')
-rw-r--r--compileopts/config.go3
1 files changed, 2 insertions, 1 deletions
diff --git a/compileopts/config.go b/compileopts/config.go
index 98dd30738..ab6de4e44 100644
--- a/compileopts/config.go
+++ b/compileopts/config.go
@@ -74,7 +74,8 @@ func (c *Config) GOARM() string {
// BuildTags returns the complete list of build tags used during this build.
func (c *Config) BuildTags() []string {
- tags := append(c.Target.BuildTags, []string{
+ tags := append([]string(nil), c.Target.BuildTags...) // copy slice (avoid a race)
+ tags = append(tags, []string{
"tinygo", // that's the compiler
"purego", // to get various crypto packages to work
"math_big_pure_go", // to get math/big to work