]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
monmaptool: Don't call set_port on an invalid address 40758/head
authorBrad Hubbard <bhubbard@redhat.com>
Wed, 25 Nov 2020 01:57:37 +0000 (11:57 +1000)
committerNathan Cutler <ncutler@suse.com>
Sat, 10 Apr 2021 18:02:25 +0000 (20:02 +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 a02d95c14ce54830d6b91aad8aebc5003d863479..068d45a46433403d2d483815355d89c93b37c002 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 3016d2c53fc7033db8f928d143df2726db9da6f0..db1f20720a948ad8ba9488d682c382c1d9f40b92 100644 (file)
@@ -440,6 +440,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(ceph::buffer::list::const_iterator& bl)
index ad41bfb14d80fd3f2bd53c7b34f5d5f5a49fb961..7dd905538cbd81e9b244daa507891160063a3f31 100644 (file)
@@ -230,7 +230,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;
       }