]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
msg/msg_types: entity_addr_t: fix empty string parse cases
authorSage Weil <sage@redhat.com>
Thu, 10 Jan 2019 19:12:34 +0000 (13:12 -0600)
committerSage Weil <sage@redhat.com>
Wed, 16 Jan 2019 14:31:43 +0000 (08:31 -0600)
Signed-off-by: Sage Weil <sage@redhat.com>
src/msg/msg_types.cc
src/test/test_addrs.cc

index bc63047604f42a1486a8e3e4f0e6efa65ca3d37e..c39e4e404fa6cd296e2e5a051c8d13d0f9e98ed5 100644 (file)
@@ -67,6 +67,9 @@ bool entity_addr_t::parse(const char *s, const char **end, int default_type)
   *this = entity_addr_t();
 
   const char *start = s;
+  if (end) {
+    *end = s;
+  }
 
   int newtype;
   if (strncmp("v1:", s, 3) == 0) {
@@ -229,6 +232,8 @@ bool entity_addrvec_t::parse(const char *s, const char **end)
   const char *static_end;
   if (!end) {
     end = &static_end;
+  } else {
+    *end = s;
   }
   v.clear();
   while (*s) {
index 155f8eb4bf1d8a89a986926c22656069329805c7..0b68f6f4022e3f6e5bed311b830c106db09a7e9d 100644 (file)
@@ -26,10 +26,10 @@ const char *addr_checks[][3] = {
   { "127.0.0.1 foo", "v2:127.0.0.1:0/0", " foo" },
   { "127.0.0.1:1234 foo", "v2:127.0.0.1:1234/0", " foo" },
   { "127.0.0.1:1234/5678 foo", "v2:127.0.0.1:1234/5678", " foo" },
-  { "1.2.3:4 a", "", "" },
+  { "1.2.3:4 a", "", "1.2.3:4 a" },
   { "2607:f298:4:2243::5522", "v2:[2607:f298:4:2243::5522]:0/0", "" },
   { "[2607:f298:4:2243::5522]", "v2:[2607:f298:4:2243::5522]:0/0", "" },
-  { "2607:f298:4:2243::5522a", "", "" },
+  { "2607:f298:4:2243::5522a", "", "2607:f298:4:2243::5522a" },
   { "[2607:f298:4:2243::5522]a", "v2:[2607:f298:4:2243::5522]:0/0", "a" },
   { "[2607:f298:4:2243::5522]:1234a", "v2:[2607:f298:4:2243::5522]:1234/0", "a" },
   { "2001:0db8:85a3:0000:0000:8a2e:0370:7334", "v2:[2001:db8:85a3::8a2e:370:7334]:0/0", "" },