]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cephfs-journal-tool: fix crash with empty argv
authorXiubo Li <xiubli@redhat.com>
Tue, 31 Dec 2019 06:57:51 +0000 (01:57 -0500)
committerNathan Cutler <ncutler@suse.com>
Mon, 27 Jan 2020 16:44:42 +0000 (17:44 +0100)
If the argument is empty, it will be better to give a hint
instead of crashing.

Fixes: https://tracker.ceph.com/issues/43438
Signed-off-by: Xiubo Li <xiubli@redhat.com>
(cherry picked from commit 2e38246ba24ddf48afa6c3a631e3aaa5e5743c93)

src/tools/cephfs/JournalTool.cc

index 29dca56df00c24cc69f00beea8ef1b72f25267c7..57bead838c44b2b76709bd0fb865290655050ef3 100644 (file)
@@ -224,6 +224,11 @@ bool JournalTool::can_execute_for_all_ranks(const std::string &mode,
  */
 int JournalTool::main_journal(std::vector<const char*> &argv)
 {
+  if (argv.empty()) {
+    derr << "Missing journal command, please see help" << dendl;
+    return -EINVAL;
+  }
+
   std::string command = argv[0];
   if (command == "inspect") {
     return journal_inspect();
@@ -291,8 +296,8 @@ int JournalTool::main_header(std::vector<const char*> &argv)
     ceph_assert(js.header != NULL);
   }
 
-  if (argv.size() == 0) {
-    derr << "Invalid header command, must be [get|set]" << dendl;
+  if (argv.empty()) {
+    derr << "Missing header command, must be [get|set]" << dendl;
     return -EINVAL;
   }
   std::vector<const char *>::iterator arg = argv.begin();
@@ -367,8 +372,12 @@ int JournalTool::main_event(std::vector<const char*> &argv)
 {
   int r;
 
-  std::vector<const char*>::iterator arg = argv.begin();
+  if (argv.empty()) {
+    derr << "Missing event command, please see help" << dendl;
+    return -EINVAL;
+  }
 
+  std::vector<const char*>::iterator arg = argv.begin();
   std::string command = *(arg++);
   if (command != "get" && command != "splice" && command != "recover_dentries") {
     derr << "Unknown argument '" << command << "'" << dendl;