aboutsummaryrefslogtreecommitdiff
path: root/src/testing/testing.go
diff options
context:
space:
mode:
authorSean Liao <sean@liao.dev>2025-05-11 22:36:58 +0100
committerSean Liao <sean@liao.dev>2025-05-12 12:34:50 -0700
commitac992f2614ee3abef8eb01ed8b7d5b4024cda48f (patch)
treeae92a29748232b3d1d63c0f85c11bc681c7db4be /src/testing/testing.go
parent8cfcad8da82a01296cfcdb8c6ab7b0b726534e21 (diff)
downloadgo-ac992f2614ee3abef8eb01ed8b7d5b4024cda48f.tar.xz
testing: limit TempDir name length
Fixes #71742 Change-Id: Ibef8f7f0a36b25f181062c4d2f84279a97e467a4 Reviewed-on: https://go-review.googlesource.com/c/go/+/671577 Reviewed-by: Damien Neil <dneil@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
Diffstat (limited to 'src/testing/testing.go')
-rw-r--r--src/testing/testing.go7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/testing/testing.go b/src/testing/testing.go
index 78681b605b..d50abea32f 100644
--- a/src/testing/testing.go
+++ b/src/testing/testing.go
@@ -1244,6 +1244,11 @@ func (c *common) TempDir() string {
if nonExistent {
c.Helper()
+ pattern := c.Name()
+ // Limit length of file names on disk.
+ // Invalid runes from slicing are dropped by strings.Map below.
+ pattern = pattern[:min(len(pattern), 64)]
+
// Drop unusual characters (such as path separators or
// characters interacting with globs) from the directory name to
// avoid surprising os.MkdirTemp behavior.
@@ -1263,7 +1268,7 @@ func (c *common) TempDir() string {
}
return -1
}
- pattern := strings.Map(mapper, c.Name())
+ pattern = strings.Map(mapper, pattern)
c.tempDir, c.tempDirErr = os.MkdirTemp("", pattern)
if c.tempDirErr == nil {
c.Cleanup(func() {