[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#72756: Potential Bug/Vuln in test.c
From: |
Paul Eggert |
Subject: |
bug#72756: Potential Bug/Vuln in test.c |
Date: |
Wed, 21 Aug 2024 23:21:07 -0700 |
User-agent: |
Mozilla Thunderbird |
I don't see a bug there. 'test' is behaving as documented.
Expectation:
`var=''; [ -n $var ]; echo $?` should NOT return `0`
This expectation is incorrect, because that command should exit with
status 0. This is because the command '[ -n $var ]' is equivalent to:
[ -n ]
which is equivalent to:
test -n
and this is is defined to exit successfully, because '-n' is not the
empty string.
The presence of the shell variable is irrelevant, because the shell
omits the expansion of $var in the context you give.
Admittedly the usage of "test" is confusing, but it's been standardized
for decades and it's not something we'd lightly change. You can see the
current standard here:
https://pubs.opengroup.org/onlinepubs/9799919799/utilities/test.html
and the relevant text says:
1 argument:
Exit true (0) if $1 is not null; otherwise, exit false.