From: An Long <lan@suse.com>
To: fstests@vger.kernel.org
Cc: An Long <lan@suse.com>
Subject: [PATCH v2 2/2] common/rc: fix input value to _scratch_mkfs_sized
Date: Thu, 16 Jun 2022 12:38:45 +0800 [thread overview]
Message-ID: <20220616043845.14320-3-lan@suse.com> (raw)
In-Reply-To: <20220616043845.14320-1-lan@suse.com>
_scratch_mkfs_sized only receive integer number of bytes as a valid
input. But if the MKFS_OPTIONS variable exists, it will use the value of
block size in MKFS_OPTIONS to override input. In case of
MKFS_OPTIONS="-b 4k", would result in blocksize=4 but not 4096. This
will give errors to ext2/3/4 etc, and brings potential bugs to xfs or
btrfs.
In addition, since we can receive various strings, so remove integer
number check.
This patch depends on patch ("common/rc: add _parse_size_from_string").
Signed-off-by: An Long <lan@suse.com>
---
V1 -> V2:
- Rename _parse_size_from_string to _parse_size_string
- Add dependency patch info to commit message
---
common/rc | 18 ++++++------------
1 file changed, 6 insertions(+), 12 deletions(-)
diff --git a/common/rc b/common/rc
index 09ffafa4..9b5d2f72 100644
--- a/common/rc
+++ b/common/rc
@@ -1077,7 +1077,7 @@ _parse_size_string()
}
# Create fs of certain size on scratch device
-# _scratch_mkfs_sized <size in bytes> [optional blocksize]
+# _scratch_mkfs_sized <size> [optional blocksize]
_scratch_mkfs_sized()
{
local fssize=$1
@@ -1086,13 +1086,13 @@ _scratch_mkfs_sized()
case $FSTYP in
xfs)
- def_blksz=`echo $MKFS_OPTIONS | sed -rn 's/.*-b ?size= ?+([0-9]+).*/\1/p'`
+ def_blksz=`echo $MKFS_OPTIONS | sed -rn 's/.*-b ?size= ?+([0-9]+[a-zA-Z]?).*/\1/p'`
;;
btrfs)
- def_blksz=`echo $MKFS_OPTIONS | sed -rn 's/.*-s ?+([0-9]+).*/\1/p'`
+ def_blksz=`echo $MKFS_OPTIONS | sed -rn 's/.*-s ?+([0-9]+[a-zA-Z]?).*/\1/p'`
;;
ext2|ext3|ext4|ext4dev|udf|reiser4|ocfs2|reiserfs)
- def_blksz=`echo $MKFS_OPTIONS | sed -rn 's/.*-b ?+([0-9]+).*/\1/p'`
+ def_blksz=`echo $MKFS_OPTIONS | sed -rn 's/.*-b ?+([0-9]+[a-zA-Z]?).*/\1/p'`
;;
jfs)
def_blksz=4096
@@ -1101,14 +1101,8 @@ _scratch_mkfs_sized()
[ -n "$def_blksz" ] && blocksize=$def_blksz
[ -z "$blocksize" ] && blocksize=4096
-
- local re='^[0-9]+$'
- if ! [[ $fssize =~ $re ]] ; then
- _notrun "error: _scratch_mkfs_sized: fs size \"$fssize\" not an integer."
- fi
- if ! [[ $blocksize =~ $re ]] ; then
- _notrun "error: _scratch_mkfs_sized: block size \"$blocksize\" not an integer."
- fi
+ blocksize=$(_parse_size_string $blocksize)
+ fssize=$(_parse_size_string $fssize)
local blocks=`expr $fssize / $blocksize`
--
2.35.3
next prev parent reply other threads:[~2022-06-16 4:39 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-16 4:38 [PATCH v2 0/2] Fix input value to _scratch_mkfs_sized An Long
2022-06-16 4:38 ` [PATCH v2 1/2] common/rc: add _parse_size_string An Long
2022-06-16 15:25 ` Gabriel Krisman Bertazi
2022-06-17 6:45 ` Long An
2022-06-16 4:38 ` An Long [this message]
2022-06-17 3:58 ` [PATCH v2 0/2] Fix input value to _scratch_mkfs_sized Dave Chinner
2022-06-17 7:03 ` Long An
2022-06-17 17:52 ` Zorro Lang
2022-06-17 22:24 ` Dave Chinner
2022-06-18 3:14 ` Zorro Lang
2022-06-20 23:12 ` Dave Chinner
2022-06-21 4:05 ` Zorro Lang
2022-06-21 4:25 ` Long An
2022-06-21 4:40 ` Zorro Lang
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=20220616043845.14320-3-lan@suse.com \
--to=lan@suse.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).