From: Dave Chinner <david@fromorbit.com>
To: linux-xfs@vger.kernel.org
Subject: [PATCH 4/5] xfsprogs: fix sliently borken option parsing
Date: Tue, 24 Mar 2020 11:19:27 +1100 [thread overview]
Message-ID: <20200324001928.17894-5-david@fromorbit.com> (raw)
In-Reply-To: <20200324001928.17894-1-david@fromorbit.com>
From: Dave Chinner <dchinner@redhat.com>
When getopt() is passed an option string like "-m -n" and the
parameter m is defined as "m:", getopt returns a special error
to indication that the optstring started with a "-". Any getopt()
caller that is just catching the "?" error character will not
not catch this special error, so it silently eats the parameter
following -m.
Lots of getopt loops in xfsprogs have this issue. Convert them all
to just use a "default:" to catch anything unexpected.
Signed-off-by: Dave Chinner <dchinner@redhat.com>
---
copy/xfs_copy.c | 2 +-
db/freesp.c | 2 +-
db/init.c | 7 ++-----
growfs/xfs_growfs.c | 1 -
io/copy_file_range.c | 2 ++
logprint/logprint.c | 2 +-
mkfs/xfs_mkfs.c | 2 +-
repair/xfs_repair.c | 2 +-
scrub/xfs_scrub.c | 2 --
spaceman/freesp.c | 1 -
spaceman/prealloc.c | 1 -
11 files changed, 9 insertions(+), 15 deletions(-)
diff --git a/copy/xfs_copy.c b/copy/xfs_copy.c
index 91c2ae01683b..c4f9f34981ca 100644
--- a/copy/xfs_copy.c
+++ b/copy/xfs_copy.c
@@ -584,7 +584,7 @@ main(int argc, char **argv)
case 'V':
printf(_("%s version %s\n"), progname, VERSION);
exit(0);
- case '?':
+ default:
usage();
}
}
diff --git a/db/freesp.c b/db/freesp.c
index 903c60d7380a..6f2346665847 100644
--- a/db/freesp.c
+++ b/db/freesp.c
@@ -177,7 +177,7 @@ init(
case 's':
summaryflag = 1;
break;
- case '?':
+ default:
return usage();
}
}
diff --git a/db/init.c b/db/init.c
index 61eea111f017..ac649fbddbb9 100644
--- a/db/init.c
+++ b/db/init.c
@@ -84,15 +84,12 @@ init(
case 'V':
printf(_("%s version %s\n"), progname, VERSION);
exit(0);
- case '?':
+ default:
usage();
- /*NOTREACHED*/
}
}
- if (optind + 1 != argc) {
+ if (optind + 1 != argc)
usage();
- /*NOTREACHED*/
- }
fsdevice = argv[optind];
if (!x.disfile)
diff --git a/growfs/xfs_growfs.c b/growfs/xfs_growfs.c
index d27e3b94e0c4..a68b515de40d 100644
--- a/growfs/xfs_growfs.c
+++ b/growfs/xfs_growfs.c
@@ -120,7 +120,6 @@ main(int argc, char **argv)
case 'V':
printf(_("%s version %s\n"), progname, VERSION);
exit(0);
- case '?':
default:
usage();
}
diff --git a/io/copy_file_range.c b/io/copy_file_range.c
index fb5702e1faad..4c4332c6e5ec 100644
--- a/io/copy_file_range.c
+++ b/io/copy_file_range.c
@@ -127,6 +127,8 @@ copy_range_f(int argc, char **argv)
/* Expect no src_path arg */
src_path_arg = 0;
break;
+ default:
+ return command_usage(©_range_cmd);
}
}
diff --git a/logprint/logprint.c b/logprint/logprint.c
index 511a32aca726..e882c5d44397 100644
--- a/logprint/logprint.c
+++ b/logprint/logprint.c
@@ -193,7 +193,7 @@ main(int argc, char **argv)
case 'V':
printf(_("%s version %s\n"), progname, VERSION);
exit(0);
- case '?':
+ default:
usage();
}
}
diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
index f14ce8db5a74..039b1dcc5afa 100644
--- a/mkfs/xfs_mkfs.c
+++ b/mkfs/xfs_mkfs.c
@@ -3679,7 +3679,7 @@ main(
case 'V':
printf(_("%s version %s\n"), progname, VERSION);
exit(0);
- case '?':
+ default:
unknown(optopt, "");
}
}
diff --git a/repair/xfs_repair.c b/repair/xfs_repair.c
index 4d37ddc64906..e509fdeb66fe 100644
--- a/repair/xfs_repair.c
+++ b/repair/xfs_repair.c
@@ -326,7 +326,7 @@ process_args(int argc, char **argv)
case 'e':
report_corrected = true;
break;
- case '?':
+ default:
usage();
}
}
diff --git a/scrub/xfs_scrub.c b/scrub/xfs_scrub.c
index 014c54dd76b2..33b876f2147a 100644
--- a/scrub/xfs_scrub.c
+++ b/scrub/xfs_scrub.c
@@ -671,8 +671,6 @@ main(
case 'x':
scrub_data = true;
break;
- case '?':
- /* fall through */
default:
usage();
}
diff --git a/spaceman/freesp.c b/spaceman/freesp.c
index 92cdb7439427..de301c195fb3 100644
--- a/spaceman/freesp.c
+++ b/spaceman/freesp.c
@@ -310,7 +310,6 @@ init(
case 's':
summaryflag = 1;
break;
- case '?':
default:
return command_usage(&freesp_cmd);
}
diff --git a/spaceman/prealloc.c b/spaceman/prealloc.c
index e5d857bdd334..6fcbb461125b 100644
--- a/spaceman/prealloc.c
+++ b/spaceman/prealloc.c
@@ -56,7 +56,6 @@ prealloc_f(
eofb.eof_min_file_size = cvtnum(fsgeom->blocksize,
fsgeom->sectsize, optarg);
break;
- case '?':
default:
return command_usage(&prealloc_cmd);
}
--
2.26.0.rc2
next prev parent reply other threads:[~2020-03-24 0:19 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-24 0:19 [PATCH 0/5] xfsprogs: miscellenaous patches Dave Chinner
2020-03-24 0:19 ` [PATCH 1/5] mkfs: use cvtnum from libfrog Dave Chinner
2020-03-24 8:42 ` Christoph Hellwig
2020-03-24 0:19 ` [PATCH 2/5] xfsprogs: Fix --disable-static option build Dave Chinner
2020-03-24 8:43 ` Christoph Hellwig
2020-03-24 0:19 ` [PATCH 3/5] xfsprogs: LDFLAGS comes from configure, not environment Dave Chinner
2020-03-24 8:44 ` Christoph Hellwig
2020-03-24 0:19 ` Dave Chinner [this message]
2020-03-24 8:44 ` [PATCH 4/5] xfsprogs: fix sliently borken option parsing Christoph Hellwig
2020-03-24 20:44 ` Darrick J. Wong
2020-03-24 0:19 ` [PATCH 5/5] xfs_io: set exitcode on failure appropriately Dave Chinner
2020-03-24 20:47 ` Darrick J. Wong
2020-03-24 23:05 ` Dave Chinner
2020-03-24 20:57 ` Eric Sandeen
2020-03-24 23:12 ` Dave Chinner
2020-03-24 23:24 ` Darrick J. Wong
2020-03-24 23:44 ` Dave Chinner
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=20200324001928.17894-5-david@fromorbit.com \
--to=david@fromorbit.com \
--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 NNTP newsgroup(s).