]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
json_formattable: fix out of bounds array entity removal
authorYehuda Sadeh <yehuda@redhat.com>
Fri, 13 Apr 2018 02:23:19 +0000 (19:23 -0700)
committerYehuda Sadeh <yehuda@redhat.com>
Fri, 13 Apr 2018 02:24:45 +0000 (19:24 -0700)
Signed-off-by: Yehuda Sadeh <yehuda@redhat.com>
src/common/ceph_json.cc

index 231eb0ee57efda3cf8ec51996b1f0579e7c0dc7b..f748bd290c4c7469164dd4cc2d2fcbccaed0bb42 100644 (file)
@@ -809,7 +809,11 @@ int JSONFormattable::erase(const string& name)
     if (last_entity.is_obj) {
       parent->obj.erase(last_entity.name);
     } else {
-      parent->arr.erase(parent->arr.begin() + last_entity.index);
+      int index = (last_entity.index >= 0 ? last_entity.index : parent->arr.size() + last_entity.index);
+      if (index < 0 || (size_t)index >= parent->arr.size()) {
+        return 0;
+      }
+      parent->arr.erase(parent->arr.begin() + index);
     }
   }