From 3672a09a48464d18d0c669cc3590d13091a2e77a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Felix=20Geisend=C3=B6rfer?=
 <felix.geisendoerfer@datadoghq.com>
Date: Thu, 24 Apr 2025 16:38:58 +0200
Subject: [PATCH] runtime/debug: update SetCrashOutput example to not pass
 parent env vars

Fixes #73490

Change-Id: I500fa73f4215c7f490779f53c1c2c0d775f51a95
Reviewed-on: https://go-review.googlesource.com/c/go/+/667775
Reviewed-by: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
---
 src/runtime/debug/example_monitor_test.go | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/runtime/debug/example_monitor_test.go b/src/runtime/debug/example_monitor_test.go
index 3b8f4dccd9f..ed6757df855 100644
--- a/src/runtime/debug/example_monitor_test.go
+++ b/src/runtime/debug/example_monitor_test.go
@@ -84,7 +84,10 @@ func monitor() {
 		log.Fatal(err)
 	}
 	cmd := exec.Command(exe, "-test.run=^ExampleSetCrashOutput_monitor$")
-	cmd.Env = append(os.Environ(), monitorVar+"=1")
+	// Be selective in which variables we allow the child to inherit.
+	// Depending on the application, some may be necessary,
+	// while others (e.g. GOGC, GOMEMLIMIT) may be harmful; see #73490.
+	cmd.Env = []string{monitorVar + "=1"}
 	cmd.Stderr = os.Stderr
 	cmd.Stdout = os.Stderr
 	pipe, err := cmd.StdinPipe()
-- 
GitLab