From: Andrey Albershteyn <aalbersh@redhat.com>
To: cem@kernel.org, linux-xfs@vger.kernel.org
Cc: djwong@kernel.org, hch@infradead.org,
Andrey Albershteyn <aalbersh@redhat.com>,
Christoph Hellwig <hch@lst.de>
Subject: [PATCH v3 3/3] xfs_repair: catch strtol() errors
Date: Wed, 17 Apr 2024 18:19:31 +0200 [thread overview]
Message-ID: <20240417161931.964526-4-aalbersh@redhat.com> (raw)
In-Reply-To: <20240417161931.964526-1-aalbersh@redhat.com>
strtol() sets errno if string parsing. Abort and tell user which
parameter is wrong.
Signed-off-by: Andrey Albershteyn <aalbersh@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
---
repair/xfs_repair.c | 40 +++++++++++++++++++++++++++++++++++++++-
1 file changed, 39 insertions(+), 1 deletion(-)
diff --git a/repair/xfs_repair.c b/repair/xfs_repair.c
index 2ceea87dc57d..2fc89dac345d 100644
--- a/repair/xfs_repair.c
+++ b/repair/xfs_repair.c
@@ -252,14 +252,22 @@ process_args(int argc, char **argv)
if (!val)
do_abort(
_("-o bhash requires a parameter\n"));
+ errno = 0;
libxfs_bhash_size = (int)strtol(val, NULL, 0);
+ if (errno)
+ do_abort(
+ _("-o bhash invalid parameter: %s\n"), strerror(errno));
bhash_option_used = 1;
break;
case AG_STRIDE:
if (!val)
do_abort(
_("-o ag_stride requires a parameter\n"));
+ errno = 0;
ag_stride = (int)strtol(val, NULL, 0);
+ if (errno)
+ do_abort(
+ _("-o ag_stride invalid parameter: %s\n"), strerror(errno));
break;
case FORCE_GEO:
if (val)
@@ -272,19 +280,31 @@ process_args(int argc, char **argv)
if (!val)
do_abort(
_("-o phase2_threads requires a parameter\n"));
+ errno = 0;
phase2_threads = (int)strtol(val, NULL, 0);
+ if (errno)
+ do_abort(
+ _("-o phase2_threads invalid parameter: %s\n"), strerror(errno));
break;
case BLOAD_LEAF_SLACK:
if (!val)
do_abort(
_("-o debug_bload_leaf_slack requires a parameter\n"));
+ errno = 0;
bload_leaf_slack = (int)strtol(val, NULL, 0);
+ if (errno)
+ do_abort(
+ _("-o debug_bload_leaf_slack invalid parameter: %s\n"), strerror(errno));
break;
case BLOAD_NODE_SLACK:
if (!val)
do_abort(
_("-o debug_bload_node_slack requires a parameter\n"));
+ errno = 0;
bload_node_slack = (int)strtol(val, NULL, 0);
+ if (errno)
+ do_abort(
+ _("-o debug_bload_node_slack invalid parameter: %s\n"), strerror(errno));
break;
case NOQUOTA:
quotacheck_skip();
@@ -305,7 +325,11 @@ process_args(int argc, char **argv)
if (!val)
do_abort(
_("-c lazycount requires a parameter\n"));
+ errno = 0;
lazy_count = (int)strtol(val, NULL, 0);
+ if (errno)
+ do_abort(
+ _("-o lazycount invalid parameter: %s\n"), strerror(errno));
convert_lazy_count = 1;
break;
case CONVERT_INOBTCOUNT:
@@ -356,7 +380,11 @@ process_args(int argc, char **argv)
if (bhash_option_used)
do_abort(_("-m option cannot be used with "
"-o bhash option\n"));
+ errno = 0;
max_mem_specified = strtol(optarg, NULL, 0);
+ if (errno)
+ do_abort(
+ _("%s: invalid memory amount: %s\n"), optarg, strerror(errno));
break;
case 'L':
zap_log = 1;
@@ -377,7 +405,11 @@ process_args(int argc, char **argv)
do_prefetch = 0;
break;
case 't':
+ errno = 0;
report_interval = strtol(optarg, NULL, 0);
+ if (errno)
+ do_abort(
+ _("%s: invalid interval: %s\n"), optarg, strerror(errno));
break;
case 'e':
report_corrected = true;
@@ -397,8 +429,14 @@ process_args(int argc, char **argv)
usage();
p = getenv("XFS_REPAIR_FAIL_AFTER_PHASE");
- if (p)
+ if (p) {
+ errno = 0;
fail_after_phase = (int)strtol(p, NULL, 0);
+ if (errno)
+ do_abort(
+ _("%s: invalid phase in XFS_REPAIR_FAIL_AFTER_PHASE: %s\n"),
+ p, strerror(errno));
+ }
}
void __attribute__((noreturn))
--
2.42.0
prev parent reply other threads:[~2024-04-17 16:19 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-17 16:19 [PATCH v3 0/3] Refactoring and error handling from Coverity scan fixes Andrey Albershteyn
2024-04-17 16:19 ` [PATCH v3 1/3] xfs_fsr: replace atoi() with strtol() Andrey Albershteyn
2024-04-17 16:19 ` [PATCH v3 2/3] xfs_db: add helper for flist_find_type for clearer field matching Andrey Albershteyn
2024-04-17 16:19 ` Andrey Albershteyn [this message]
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=20240417161931.964526-4-aalbersh@redhat.com \
--to=aalbersh@redhat.com \
--cc=cem@kernel.org \
--cc=djwong@kernel.org \
--cc=hch@infradead.org \
--cc=hch@lst.de \
--cc=linux-xfs@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 read-only IMAP folder(s) and NNTP newsgroup(s).