From: "Darrick J. Wong" <djwong@kernel.org>
To: Andrey Albershteyn <aalbersh@redhat.com>
Cc: cem@kernel.org, linux-xfs@vger.kernel.org, hch@infradead.org
Subject: Re: [PATCH v2 1/3] xfs_fsr: replace atoi() with strtol()
Date: Wed, 17 Apr 2024 08:20:13 -0700 [thread overview]
Message-ID: <20240417152013.GT11948@frogsfrogsfrogs> (raw)
In-Reply-To: <20240417125937.917910-2-aalbersh@redhat.com>
On Wed, Apr 17, 2024 at 02:59:35PM +0200, Andrey Albershteyn wrote:
> Replace atoi() which silently fails with strtol() and report the
> error.
>
> Signed-off-by: Andrey Albershteyn <aalbersh@redhat.com>
> ---
> fsr/xfs_fsr.c | 26 +++++++++++++++++++++++---
> 1 file changed, 23 insertions(+), 3 deletions(-)
>
> diff --git a/fsr/xfs_fsr.c b/fsr/xfs_fsr.c
> index 02d61ef9399a..cf764755288d 100644
> --- a/fsr/xfs_fsr.c
> +++ b/fsr/xfs_fsr.c
> @@ -164,7 +164,13 @@ main(int argc, char **argv)
> usage(1);
> break;
> case 't':
> - howlong = atoi(optarg);
> + errno = 0;
> + howlong = strtol(optarg, NULL, 10);
> + if (errno) {
> + fprintf(stderr, _("%s: invalid interval: %s\n"),
"invalid runtime"?
With that fixed,
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
--D
> + optarg, strerror(errno));
> + exit(1);
> + }
> if (howlong > INT_MAX) {
> fprintf(stderr,
> _("%s: the maximum runtime is %d seconds.\n"),
> @@ -179,10 +185,24 @@ main(int argc, char **argv)
> mtab = optarg;
> break;
> case 'b':
> - argv_blksz_dio = atoi(optarg);
> + errno = 0;
> + argv_blksz_dio = strtol(optarg, NULL, 10);
> + if (errno) {
> + fprintf(stderr,
> + _("%s: invalid block size: %s\n"),
> + optarg, strerror(errno));
> + exit(1);
> + }
> break;
> case 'p':
> - npasses = atoi(optarg);
> + errno = 0;
> + npasses = strtol(optarg, NULL, 10);
> + if (errno) {
> + fprintf(stderr,
> + _("%s: invalid number of passes: %s\n"),
> + optarg, strerror(errno));
> + exit(1);
> + }
> break;
> case 'C':
> /* Testing opt: coerses frag count in result */
> --
> 2.42.0
>
>
next prev parent reply other threads:[~2024-04-17 15:20 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-17 12:59 [PATCH v2 0/3] Refactoring and error handling from Coverity scan fixes Andrey Albershteyn
2024-04-17 12:59 ` [PATCH v2 1/3] xfs_fsr: replace atoi() with strtol() Andrey Albershteyn
2024-04-17 15:20 ` Darrick J. Wong [this message]
2024-04-17 15:21 ` Christoph Hellwig
2024-04-17 12:59 ` [PATCH v2 2/3] xfs_db: add helper for flist_find_type for clearer field matching Andrey Albershteyn
2024-04-17 15:20 ` Darrick J. Wong
2024-04-17 15:22 ` Christoph Hellwig
2024-04-17 12:59 ` [PATCH v2 3/3] xfs_repair: catch strtol() errors Andrey Albershteyn
2024-04-17 15:21 ` Darrick J. Wong
2024-04-17 15:22 ` Christoph Hellwig
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=20240417152013.GT11948@frogsfrogsfrogs \
--to=djwong@kernel.org \
--cc=aalbersh@redhat.com \
--cc=cem@kernel.org \
--cc=hch@infradead.org \
--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).