]> www.infradead.org Git - users/hch/xfsprogs.git/commitdiff
xfs_fsr: replace atoi() with strtol()
authorAndrey Albershteyn <aalbersh@redhat.com>
Wed, 17 Apr 2024 16:19:29 +0000 (18:19 +0200)
committerCarlos Maiolino <cem@kernel.org>
Tue, 23 Apr 2024 13:07:05 +0000 (15:07 +0200)
Replace atoi() which silently fails with strtol() and report the
error.

Signed-off-by: Andrey Albershteyn <aalbersh@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
fsr/xfs_fsr.c

index 02d61ef9399aa4841d130de77308a70eae719b95..fdd37756030a784698001647a0b8f90940fb6864 100644 (file)
@@ -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 runtime: %s\n"),
+                                       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 */