From 49c6b4e9472f53c252126f1c9a5a6e9629967d1f Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Thu, 27 Apr 2006 20:59:42 -0400 Subject: [PATCH] Add handling for invalid option characters in debugfs subcommands Fix the debugfs commands htree_dump, dx_hash, and list_dir so they print a print a usage message when an illegal option character is given. Signed-off-by: "Theodore Ts'o" --- debugfs/ChangeLog | 7 +++++++ debugfs/htree.c | 6 ++++++ debugfs/ls.c | 3 +++ 3 files changed, 16 insertions(+) diff --git a/debugfs/ChangeLog b/debugfs/ChangeLog index d71f6d8..a9fb8a4 100644 --- a/debugfs/ChangeLog +++ b/debugfs/ChangeLog @@ -1,3 +1,10 @@ +2006-04-27 Theodore Ts'o + + * htree.c (do_htree_dump, do_dx_hash), ls.c (do_list_dir): Add + missing default case in the getopt() while/switch loop so + that we print a usage() statement when the user specified + an illegal option. + 2006-03-18 Theodore Ts'o * debugfs.c, htree.c, unused.c: Change printf statements to use diff --git a/debugfs/htree.c b/debugfs/htree.c index 6dbe426..a266cb3 100644 --- a/debugfs/htree.c +++ b/debugfs/htree.c @@ -197,10 +197,13 @@ void do_htree_dump(int argc, char *argv[]) case 'l': long_opt++; break; + default: + goto print_usage; } } if (argc > optind+1) { + print_usage: com_err(0, 0, "Usage: htree_dump [-l] file"); goto errout; } @@ -279,9 +282,12 @@ void do_dx_hash(int argc, char *argv[]) case 'h': hash_version = atoi(optarg); break; + default: + goto print_usage; } } if (optind != argc-1) { + print_usage: com_err(argv[0], 0, "usage: dx_hash filename"); return; } diff --git a/debugfs/ls.c b/debugfs/ls.c index f1c52c9..8e97ce8 100644 --- a/debugfs/ls.c +++ b/debugfs/ls.c @@ -131,10 +131,13 @@ void do_list_dir(int argc, char *argv[]) case 'd': ls.options |= DELETED_OPT; break; + default: + goto print_usage; } } if (argc > optind+1) { + print_usage: com_err(0, 0, "Usage: ls [-l] [-d] file"); return; } -- 1.8.3.1