]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
monmaptool: Don't call set_port on an invalid address 38258/head
authorBrad Hubbard <bhubbard@redhat.com>
Wed, 25 Nov 2020 01:57:37 +0000 (11:57 +1000)
committerBrad Hubbard <bhubbard@redhat.com>
Thu, 1 Apr 2021 06:34:35 +0000 (16:34 +1000)
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>
src/msg/msg_types.cc
src/msg/msg_types.h
src/tools/monmaptool.cc

index 50a75cc86d0594d4edd34aa294b2373242d8822b..330cfba5bc35a997aad4129473ef90198b418c63 100644 (file)
@@ -64,6 +64,14 @@ void entity_inst_t::generate_test_instances(std::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 cf0574972d30d8bab280e522ae5a74e3a6fcf422..bb26d3d55baeb329564c0812f6d5e35288365cab 100644 (file)
@@ -438,6 +438,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 94aea46ad109ea37efb70bfb703d6047a66b7682..23962997d218c7ad8fa288226244607fb87969bd 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;
       }