From 36fcdfbbc5463e55581fec67141df3493fb81f7e Mon Sep 17 00:00:00 2001 From: Florian Weimer Date: Fri, 24 Jan 2025 08:04:23 +0100 Subject: Revert "stdlib: Support malloc-managed environ arrays for compatibility" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit b62759db04b8ed7f829c06f1d7c3b8fb70616493. Reason for revert: Incompatible with “env -i” and coreutils (bug 32588). Reviewed-by: H.J. Lu --- stdlib/tst-setenv-malloc.c | 64 ---------------------------------------------- 1 file changed, 64 deletions(-) delete mode 100644 stdlib/tst-setenv-malloc.c (limited to 'stdlib/tst-setenv-malloc.c') diff --git a/stdlib/tst-setenv-malloc.c b/stdlib/tst-setenv-malloc.c deleted file mode 100644 index 18a9d36842..0000000000 --- a/stdlib/tst-setenv-malloc.c +++ /dev/null @@ -1,64 +0,0 @@ -/* Test using setenv with a malloc-allocated environ variable. - Copyright (C) 2025 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -/* This test is not in the scope for POSIX or any other standard, but - some applications assume that environ is a heap-allocated pointer - after a call to setenv on an empty environment. */ - -#include -#include -#include -#include - -static const char *original_path; -static char **save_environ; - -static void -rewrite_environ (void) -{ - save_environ = environ; - environ = xmalloc (sizeof (*environ)); - *environ = NULL; - TEST_COMPARE (setenv ("A", "1", 1), 0); - TEST_COMPARE (setenv ("B", "2", 1), 0); - TEST_VERIFY (environ != save_environ); - TEST_COMPARE_STRING (environ[0], "A=1"); - TEST_COMPARE_STRING (environ[1], "B=2"); - TEST_COMPARE_STRING (environ[2], NULL); - TEST_COMPARE_STRING (getenv ("PATH"), NULL); - free (environ); - environ = save_environ; - TEST_COMPARE_STRING (getenv ("PATH"), original_path); -} - -static int -do_test (void) -{ - original_path = getenv ("PATH"); - rewrite_environ (); - - /* Test again after reallocated the environment due to an initial - setenv call. */ - TEST_COMPARE (setenv ("TST_SETENV_MALLOC", "1", 1), 0); - TEST_VERIFY (environ != save_environ); - rewrite_environ (); - - return 0; -} - -#include -- cgit v1.2.3