]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
osdmaptool: print useful error instead of crashing if osdmap is corrupt
authorSage Weil <sage@newdream.net>
Fri, 20 Aug 2010 16:31:49 +0000 (09:31 -0700)
committerSage Weil <sage@newdream.net>
Fri, 20 Aug 2010 16:31:49 +0000 (09:31 -0700)
src/osd/osd_types.h
src/osdmaptool.cc

index 8e2caca85f261fec15cf5dba0ca821c473e224fc..4b1d8d5e1511d60a96565a2cc131ac8809dc0a37 100644 (file)
@@ -797,7 +797,8 @@ struct pg_pool_t {
   void decode(bufferlist::iterator& bl) {
     __u8 struct_v;
     ::decode(struct_v, bl);
-    assert(struct_v <= CEPH_PG_POOL_VERSION);
+    if (struct_v > CEPH_PG_POOL_VERSION)
+      throw new buffer::error;
     ::decode(v, bl);
     ::decode_nohead(v.num_snaps, snaps, bl);
     removed_snaps.decode_nohead(v.num_removed_snap_intervals, bl);
index 173122ac084de0203358496ed932fa7d3fad8c75..f6e65d050fbdf3c3fdecaa4b2ab61cdf54d37de5 100644 (file)
@@ -111,8 +111,15 @@ int main(int argc, const char **argv)
   int r = 0;
   if (!(createsimple && clobber)) {
     r = bl.read_file(fn);
-    if (r >= 0)
-      osdmap.decode(bl);
+    if (r >= 0) {
+      try {
+       osdmap.decode(bl);
+      }
+      catch (buffer::error *e) {
+       cerr << me << ": error decoding osdmap '" << fn << "'" << std::endl;
+       return -1;
+      }
+    }
   }
   char buf[80];
   if (!createsimple && r < 0) {