]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
monmaptool: Don't call set_port on an invalid address 40700/head
authorBrad Hubbard <bhubbard@redhat.com>
Wed, 25 Nov 2020 01:57:37 +0000 (11:57 +1000)
committerNathan Cutler <ncutler@suse.com>
Thu, 8 Apr 2021 16:53:44 +0000 (18:53 +0200)
Verify we parse the entire address argument.

Fixes: https://tracker.ceph.com/issues/48336
Signed-off-by: Brad Hubbard <bhubbard@redhat.com>
Signed-off-by: Kefu Chai <kchai@redhat.com>
(cherry picked from commit c0aa1fdbe7b87c2fb4b572169372ec487950b03d)

src/msg/msg_types.cc
src/msg/msg_types.h
src/tools/monmaptool.cc

index 76b9585b394e3602b80b87ba88ae6664d88136a0..e2e8cbb015bff924fb5056dd60191a4d82f18b6d 100644 (file)
@@ -62,6 +62,14 @@ void entity_inst_t::generate_test_instances(list<entity_inst_t*>& o)
   o.push_back(a);
 }
 
+bool entity_addr_t::parse(const std::string_view s)
+{
+  const char* start = s.data();
+  const char* end = nullptr;
+  bool got = parse(start, &end);
+  return got && end == start + s.size();
+}
+
 bool entity_addr_t::parse(const char *s, const char **end, int default_type)
 {
   *this = entity_addr_t();
index 74d5ee30f59491d03d06520122e722079f3e9319..4fb7ec2acf7e00dac43bc9ca0b7091124843fd4d 100644 (file)
@@ -439,6 +439,7 @@ struct entity_addr_t {
     return ss.str();
   }
 
+  bool parse(const std::string_view s);
   bool parse(const char *s, const char **end = 0, int type=0);
 
   void decode_legacy_addr_after_marker(bufferlist::const_iterator& bl)
index ef819a3a5e286442c1449f48082db300fd1aed52..1eeb4f5b584d3da48e2ff0650d1e3c5727895d86 100644 (file)
@@ -229,7 +229,8 @@ int main(int argc, const char **argv)
       if (i == args.end())
        helpful_exit();
       entity_addr_t addr;
-      if (!addr.parse(*i)) {
+      if (!addr.parse(string_view{*i})) {
+        // Either we couldn't parse the address or we didn't consume the entire token
        cerr << me << ": invalid ip:port '" << *i << "'" << std::endl;
        return -1;
       }