GNU bug report logs - #72756
Potential Bug/Vuln in test.c

Previous Next

Package: coreutils;

Reported by: Nathan Hays <nathan.hays <at> nccgroup.com>

Date: Thu, 22 Aug 2024 05:47:01 UTC

Severity: normal

Done: Paul Eggert <eggert <at> cs.ucla.edu>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Thomas Wolff <towo <at> towo.net>
To: 72756 <at> debbugs.gnu.org
Subject: bug#72756: Potential Bug/Vuln in test.c
Date: Thu, 22 Aug 2024 09:29:28 +0200
[Message part 1 (text/plain, inline)]
Am 22.08.2024 um 08:54 schrieb Philip Rowlands:
> On Wed, 21 Aug 2024, at 18:29, Nathan Hays via GNU coreutils Bug Reports wrote:
>> Test:
>> ~~~bash
>> testvar=''
>> [ -n $testvar ]
>> echo -n unquote exit $?
>> [ -n "$testvar" ]
>> echo -n quote exit $?
>> [ -z $testvar ]
>> echo -z unquote exit $?
>> [ -z "$testvar" ]
>> echo -z quote exit $?
>> ~~~
> For this code snippet, the shellcheck linter reports
>
> [ -n $testvar ]
>       ^------^ SC2070: -n doesn't work with unquoted arguments. Quote or use [[ ]].
>       ^------^ SC2086: Double quote to prevent globbing and word splitting.
>
> Did you mean:
> [ -n "$testvar" ]
>
> For more information:
>    https://www.shellcheck.net/wiki/SC2070  -- -n doesn't work with unquoted arg...
It's a similar confusing syntax glitch as in shell:
# cond=true # commented out with the assumption the below condition will
not be true then
if $cond
then echo surprise # but it is
fi

Cheers
Thomas

> Cheers,
> Phil
>
[Message part 2 (text/html, inline)]

This bug report was last modified 97 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.