All of lore.kernel.org
 help / color / mirror / Atom feed
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>
Subject: [PATCH 1/2] xfs_fsr: replace atoi() with strtol()
Date: Tue, 16 Apr 2024 22:28:41 +0200	[thread overview]
Message-ID: <20240416202841.725706-3-aalbersh@redhat.com> (raw)
In-Reply-To: <20240416202841.725706-2-aalbersh@redhat.com>

Replace atoi() which silently fails with strtol() and report the
error.

Signed-off-by: Andrey Albershteyn <aalbersh@redhat.com>
---
 fsr/xfs_fsr.c | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/fsr/xfs_fsr.c b/fsr/xfs_fsr.c
index 4e29a8a2c548..5fabc965183e 100644
--- a/fsr/xfs_fsr.c
+++ b/fsr/xfs_fsr.c
@@ -164,7 +164,12 @@ main(int argc, char **argv)
 			usage(1);
 			break;
 		case 't':
-			howlong = atoi(optarg);
+			howlong = strtol(optarg, NULL, 10);
+			if (errno) {
+				fprintf(stderr, _("%s: invalid interval: %s\n"),
+					progname, strerror(errno));
+				exit(1);
+			}
 			if (howlong > INT_MAX) {
 				fprintf(stderr, _("%s: too long\n"), progname);
 				exit(1);
@@ -177,10 +182,22 @@ main(int argc, char **argv)
 			mtab = optarg;
 			break;
 		case 'b':
-			argv_blksz_dio = atoi(optarg);
+			argv_blksz_dio = strtol(optarg, NULL, 10);
+			if (errno) {
+				fprintf(stderr,
+					_("%s: invalid block size: %s\n"),
+					progname, strerror(errno));
+				exit(1);
+			}
 			break;
 		case 'p':
-			npasses = atoi(optarg);
+			npasses = strtol(optarg, NULL, 10);
+			if (errno) {
+				fprintf(stderr,
+					_("%s: invalid number of passes: %s\n"),
+					progname, strerror(errno));
+				exit(1);
+			}
 			break;
 		case 'C':
 			/* Testing opt: coerses frag count in result */
-- 
2.42.0


  reply	other threads:[~2024-04-16 20:29 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-16 20:28 [PATCH 0/2] Refactoring from Coverity scan fixes Andrey Albershteyn
2024-04-16 20:28 ` Andrey Albershteyn [this message]
2024-04-16 20:49   ` [PATCH 1/2] xfs_fsr: replace atoi() with strtol() Darrick J. Wong
2024-04-16 20:28 ` [PATCH 2/2] xfs_db: add helper for flist_find_type for clearer field matching Andrey Albershteyn
2024-04-16 20:53   ` Darrick J. Wong
2024-04-17  5:03     ` 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=20240416202841.725706-3-aalbersh@redhat.com \
    --to=aalbersh@redhat.com \
    --cc=cem@kernel.org \
    --cc=djwong@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 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.