* [PATCH] properly quote strings tested with -n
@ 2015-08-28 22:46 Eric Sandeen
2015-10-01 13:30 ` Eric Sandeen
0 siblings, 1 reply; 3+ messages in thread
From: Eric Sandeen @ 2015-08-28 22:46 UTC (permalink / raw)
To: fstests@vger.kernel.org
Per the Advanced Bash Scripting Guide:
"The -n test requires that the string be quoted within the test brackets.
Using an unquoted string with ! -z, or even just the unquoted string
alone within test bracket normally works, however, this is an unsafe
practice. Always quote a tested string."
And indeed:
$ unset FOOBAR
$ [ -n $FOOBAR ] || echo nope
$ [ -n "$FOOBAR" ] || echo nope
nope
Ran into this on a box w/o the attr program installed, and passed
_require_attrs. Quoting the string fixes this; fix it there
and other occurrences in common/* as well.
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---
diff --git a/common/attr b/common/attr
index 48c81cc..cc9cfda 100644
--- a/common/attr
+++ b/common/attr
@@ -165,7 +165,7 @@ _filter_aces_notypes()
_require_acls()
{
- [ -n $CHACL_PROG ] || _notrun "chacl command not found"
+ [ -n "$CHACL_PROG" ] || _notrun "chacl command not found"
#
# Test if chacl is able to list ACLs on the target filesystems. On really
@@ -196,9 +196,9 @@ _list_acl()
_require_attrs()
{
- [ -n $ATTR_PROG ] || _notrun "attr command not found"
- [ -n $GETFATTR_PROG ] || _notrun "getfattr command not found"
- [ -n $SETFATTR_PROG ] || _notrun "setfattr command not found"
+ [ -n "$ATTR_PROG" ] || _notrun "attr command not found"
+ [ -n "$GETFATTR_PROG" ] || _notrun "getfattr command not found"
+ [ -n "$SETFATTR_PROG" ] || _notrun "setfattr command not found"
#
# Test if chacl is able to write an attribute on the target filesystems.
diff --git a/common/quota b/common/quota
index 23be4f8..658b1c3 100644
--- a/common/quota
+++ b/common/quota
@@ -26,7 +26,7 @@
#
_require_quota()
{
- [ -n $QUOTA_PROG ] || _notrun "Quota user tools not installed"
+ [ -n "$QUOTA_PROG" ] || _notrun "Quota user tools not installed"
case $FSTYP in
ext2|ext3|ext4|ext4dev|reiserfs)
@@ -74,7 +74,7 @@ _require_xfs_quota()
if [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ]; then
_notrun "Quotas not supported on realtime scratch device"
fi
- [ -n $XFS_QUOTA_PROG ] || _notrun "XFS quota user tools not installed"
+ [ -n "$XFS_QUOTA_PROG" ] || _notrun "XFS quota user tools not installed"
}
#
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] properly quote strings tested with -n
2015-08-28 22:46 [PATCH] properly quote strings tested with -n Eric Sandeen
@ 2015-10-01 13:30 ` Eric Sandeen
2015-10-01 13:36 ` Alex Elder
0 siblings, 1 reply; 3+ messages in thread
From: Eric Sandeen @ 2015-10-01 13:30 UTC (permalink / raw)
To: Eric Sandeen, fstests@vger.kernel.org
Ping?
On 8/28/15 5:46 PM, Eric Sandeen wrote:
> Per the Advanced Bash Scripting Guide:
>
> "The -n test requires that the string be quoted within the test brackets.
> Using an unquoted string with ! -z, or even just the unquoted string
> alone within test bracket normally works, however, this is an unsafe
> practice. Always quote a tested string."
>
> And indeed:
>
> $ unset FOOBAR
> $ [ -n $FOOBAR ] || echo nope
> $ [ -n "$FOOBAR" ] || echo nope
> nope
>
> Ran into this on a box w/o the attr program installed, and passed
> _require_attrs. Quoting the string fixes this; fix it there
> and other occurrences in common/* as well.
>
> Signed-off-by: Eric Sandeen <sandeen@redhat.com>
> ---
>
> diff --git a/common/attr b/common/attr
> index 48c81cc..cc9cfda 100644
> --- a/common/attr
> +++ b/common/attr
> @@ -165,7 +165,7 @@ _filter_aces_notypes()
>
> _require_acls()
> {
> - [ -n $CHACL_PROG ] || _notrun "chacl command not found"
> + [ -n "$CHACL_PROG" ] || _notrun "chacl command not found"
>
> #
> # Test if chacl is able to list ACLs on the target filesystems. On really
> @@ -196,9 +196,9 @@ _list_acl()
>
> _require_attrs()
> {
> - [ -n $ATTR_PROG ] || _notrun "attr command not found"
> - [ -n $GETFATTR_PROG ] || _notrun "getfattr command not found"
> - [ -n $SETFATTR_PROG ] || _notrun "setfattr command not found"
> + [ -n "$ATTR_PROG" ] || _notrun "attr command not found"
> + [ -n "$GETFATTR_PROG" ] || _notrun "getfattr command not found"
> + [ -n "$SETFATTR_PROG" ] || _notrun "setfattr command not found"
>
> #
> # Test if chacl is able to write an attribute on the target filesystems.
> diff --git a/common/quota b/common/quota
> index 23be4f8..658b1c3 100644
> --- a/common/quota
> +++ b/common/quota
> @@ -26,7 +26,7 @@
> #
> _require_quota()
> {
> - [ -n $QUOTA_PROG ] || _notrun "Quota user tools not installed"
> + [ -n "$QUOTA_PROG" ] || _notrun "Quota user tools not installed"
>
> case $FSTYP in
> ext2|ext3|ext4|ext4dev|reiserfs)
> @@ -74,7 +74,7 @@ _require_xfs_quota()
> if [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ]; then
> _notrun "Quotas not supported on realtime scratch device"
> fi
> - [ -n $XFS_QUOTA_PROG ] || _notrun "XFS quota user tools not installed"
> + [ -n "$XFS_QUOTA_PROG" ] || _notrun "XFS quota user tools not installed"
> }
>
> #
>
> --
> To unsubscribe from this list: send the line "unsubscribe fstests" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] properly quote strings tested with -n
2015-10-01 13:30 ` Eric Sandeen
@ 2015-10-01 13:36 ` Alex Elder
0 siblings, 0 replies; 3+ messages in thread
From: Alex Elder @ 2015-10-01 13:36 UTC (permalink / raw)
To: Eric Sandeen, Eric Sandeen, fstests@vger.kernel.org
On 10/01/2015 08:30 AM, Eric Sandeen wrote:
> Ping?
I no longer have your original message. But this is
one I know and love (hate) from past experience with shell
scripting. I eventually started always using "${FOO}"
in scripts to make sure I never had to chase down this
sort of bug, ever again.
I did not look at the whole set of fstests code
to see if you hit them all, but everything I see
here looks good.
Reviewed-by: Alex Elder <elder@linaro.org>
> On 8/28/15 5:46 PM, Eric Sandeen wrote:
>> Per the Advanced Bash Scripting Guide:
>>
>> "The -n test requires that the string be quoted within the test brackets.
>> Using an unquoted string with ! -z, or even just the unquoted string
>> alone within test bracket normally works, however, this is an unsafe
>> practice. Always quote a tested string."
>>
>> And indeed:
>>
>> $ unset FOOBAR
>> $ [ -n $FOOBAR ] || echo nope
>> $ [ -n "$FOOBAR" ] || echo nope
>> nope
>>
>> Ran into this on a box w/o the attr program installed, and passed
>> _require_attrs. Quoting the string fixes this; fix it there
>> and other occurrences in common/* as well.
>>
>> Signed-off-by: Eric Sandeen <sandeen@redhat.com>
>> ---
>>
>> diff --git a/common/attr b/common/attr
>> index 48c81cc..cc9cfda 100644
>> --- a/common/attr
>> +++ b/common/attr
>> @@ -165,7 +165,7 @@ _filter_aces_notypes()
>>
>> _require_acls()
>> {
>> - [ -n $CHACL_PROG ] || _notrun "chacl command not found"
>> + [ -n "$CHACL_PROG" ] || _notrun "chacl command not found"
>>
>> #
>> # Test if chacl is able to list ACLs on the target filesystems. On really
>> @@ -196,9 +196,9 @@ _list_acl()
>>
>> _require_attrs()
>> {
>> - [ -n $ATTR_PROG ] || _notrun "attr command not found"
>> - [ -n $GETFATTR_PROG ] || _notrun "getfattr command not found"
>> - [ -n $SETFATTR_PROG ] || _notrun "setfattr command not found"
>> + [ -n "$ATTR_PROG" ] || _notrun "attr command not found"
>> + [ -n "$GETFATTR_PROG" ] || _notrun "getfattr command not found"
>> + [ -n "$SETFATTR_PROG" ] || _notrun "setfattr command not found"
>>
>> #
>> # Test if chacl is able to write an attribute on the target filesystems.
>> diff --git a/common/quota b/common/quota
>> index 23be4f8..658b1c3 100644
>> --- a/common/quota
>> +++ b/common/quota
>> @@ -26,7 +26,7 @@
>> #
>> _require_quota()
>> {
>> - [ -n $QUOTA_PROG ] || _notrun "Quota user tools not installed"
>> + [ -n "$QUOTA_PROG" ] || _notrun "Quota user tools not installed"
>>
>> case $FSTYP in
>> ext2|ext3|ext4|ext4dev|reiserfs)
>> @@ -74,7 +74,7 @@ _require_xfs_quota()
>> if [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ]; then
>> _notrun "Quotas not supported on realtime scratch device"
>> fi
>> - [ -n $XFS_QUOTA_PROG ] || _notrun "XFS quota user tools not installed"
>> + [ -n "$XFS_QUOTA_PROG" ] || _notrun "XFS quota user tools not installed"
>> }
>>
>> #
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe fstests" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>>
> --
> To unsubscribe from this list: send the line "unsubscribe fstests" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-10-01 13:36 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-28 22:46 [PATCH] properly quote strings tested with -n Eric Sandeen
2015-10-01 13:30 ` Eric Sandeen
2015-10-01 13:36 ` Alex Elder
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox