All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Sandeen <sandeen@redhat.com>
To: "fstests@vger.kernel.org" <fstests@vger.kernel.org>
Subject: [PATCH] properly quote strings tested with -n
Date: Fri, 28 Aug 2015 17:46:04 -0500	[thread overview]
Message-ID: <55E0E4AC.5050607@redhat.com> (raw)

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"
 }
 
 #


             reply	other threads:[~2015-08-28 22:46 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-28 22:46 Eric Sandeen [this message]
2015-10-01 13:30 ` [PATCH] properly quote strings tested with -n Eric Sandeen
2015-10-01 13:36   ` Alex Elder

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=55E0E4AC.5050607@redhat.com \
    --to=sandeen@redhat.com \
    --cc=fstests@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.