[compiler-rt] [scudo] Use setenv instead of putenv in ScudoCombinedTest.ZeroOnDeallocEnabledAndFlag (PR #173423)

Fabio D'Urso via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 23 14:56:31 PST 2025


https://github.com/fabio-d created https://github.com/llvm/llvm-project/pull/173423

This solves a stack-use-after-scope reported by AddressSanitizer within the unsetenv call at end of the test, due to the "Options" buffer, that we allocate on the stack, having already gone out of scope.

Unlike putenv, which stores the pointer to the passed string directly in the environment, setenv creates an internal copy.

>From f95336507d70e6bc8d0ef4bb8274f6add7a5e7de Mon Sep 17 00:00:00 2001
From: Fabio D'Urso <fdurso at google.com>
Date: Tue, 23 Dec 2025 22:35:21 +0000
Subject: [PATCH] [scudo] Use setenv instead of putenv in
 ScudoCombinedTest.ZeroOnDeallocEnabledAndFlag

This solves a stack-use-after-scope reported by AddressSanitizer
within the unsetenv call at end of the test, due to the "Options"
buffer, that we allocate on the stack, having already gone out of
scope.

Unlike putenv, which stores the pointer to the passed string
directly in the environment, setenv creates an internal copy.
---
 compiler-rt/lib/scudo/standalone/tests/combined_test.cpp | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp b/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp
index e8587ee397e2a..8b62c0e104d6b 100644
--- a/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp
+++ b/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp
@@ -1122,10 +1122,9 @@ TEST(ScudoCombinedTest, ZeroOnDeallocEnabledAndFlag) {
     for (scudo::uptr FlagValue = 128; FlagValue <= 2048; FlagValue *= 2) {
       // Set the size limit flag via the environment variable.
       char Options[256];
-      snprintf(Options, sizeof(Options),
-               "SCUDO_OPTIONS=zero_on_dealloc_max_size=%ld",
+      snprintf(Options, sizeof(Options), "zero_on_dealloc_max_size=%ld",
                static_cast<long>(FlagValue));
-      putenv(Options);
+      setenv("SCUDO_OPTIONS", Options, 1);
 
       // Creates an allocator, configured from the environment.
       using AllocatorT = TestAllocator<TestZeroOnDeallocConfig>;



More information about the llvm-commits mailing list