On 25/08/2026 03:02, Collin Funk wrote:
Bruno Haible via GNU coreutils General Discussion <[email protected]>
writes:
This week, this test fails on FreeBSD 14.0:
FAIL: tests/env/env0-from
=========================
env: environment corrupt; missing value for opaque
env: cannot unset 'A': Bad address
--- exp-sorted 2026-08-24 19:26:18.994854000 +0000
+++ out 2026-08-24 19:26:18.997699000 +0000
@@ -0,0 +1,4 @@
+B=old
+C=operand
+D=new
+opaque
env: cannot unset '': Invalid argument
env: cannot unset 'A=B': Invalid argument
env: cannot unset '': Invalid argument
env: cannot unset 'A=B': Invalid argument
FAIL tests/env/env0-from.sh (exit status: 1)
Thats annoying. FreeBSD getenv, putenv, and friends just give up upon
seeing an environment variable without a value, instead of continuing
like everyone else [1].
I don't like the attached patch, but I don't see an alternative...
Collin
[1]
https://github.com/freebsd/freebsd-src/blob/9496457f230f933afa78b0a60295d59828bff08c/lib/libc/stdlib/getenv.c#L354-L364
It seems that this validation is only done on unsetenv() on FreeBSD?
$ printf 'A=1\0A=2\0foo\0' |
src/env --env0-from=- src/env foo=bar | grep foo
foo=bar
foo
$ printf 'A=1\0A=2\0foo\0' |
src/env --env0-from=- src/env -u foo
env: environment corrupt; missing value for foo
env: cannot unset ‘foo’: Bad address
$ printf 'A=1\0A=2\0foo\0' |
src/env --env0-from=- src/env -u bar
env: environment corrupt; missing value for foo
env: cannot unset ‘bar’: Bad address
Anyway we can avoid the unsetenv() and putenv() in this case
as we're only re-execing env(1) to get a standard env list with possible
implicit entries,
we can do our manipulations before that.
The attached passes on FreeBSD 15 at least (cfarm240).
cheers,
PadraigFrom b7d35fd2dd904290eb75a04d92578a607f84c37d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <[email protected]>
Date: Tue, 25 Aug 2026 12:40:40 +0100
Subject: [PATCH] tests: env: avoid false failure on FreeBSD
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Avoid unsetenv() on a non standard environment,
as FreeBSD 14 and 15 at least fail when manipulating
such an environment with unsetenv().
$ printf 'A=1\0A=2\0foo\0' |
src/env --env0-from=- src/env foo=bar | grep foo
foo=bar
foo
$ printf 'A=1\0A=2\0foo\0' |
src/env --env0-from=- src/env -u foo
env: environment corrupt; missing value for foo
env: cannot unset ‘foo’: Bad address
$ printf 'A=1\0A=2\0foo\0' |
src/env --env0-from=- src/env -u bar
env: environment corrupt; missing value for foo
env: cannot unset ‘bar’: Bad address
* tests/env/env0-from.sh: Use routines internal to env(1)
to manipulate the environment, only delegating the
executed env(1) to adding any implicit environment variables.
Reported by Bruno Haible.
---
tests/env/env0-from.sh | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tests/env/env0-from.sh b/tests/env/env0-from.sh
index 9e54e7e47..66d46de4c 100755
--- a/tests/env/env0-from.sh
+++ b/tests/env/env0-from.sh
@@ -93,8 +93,8 @@ case $host_os in
sort all >out || framework_failure_
compare exp-sorted out || fail=1
- env -i --env0-from=base \
- "$envexe" -u A C=operand D=new >exp || fail=1
+ env -i --env0-from=base -u A C=operand D=new \
+ "$envexe" >exp || fail=1
sort exp >exp-sorted || framework_failure_
env -i --env0-from=base \
"$envexe" --env0-from=merge -u A C=operand D=new >all || fail=1
--
2.55.0