From cfdc5f0ef29f9f7c042c267d52134d21b033c70d Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Fri, 20 Aug 2010 09:31:49 -0700 Subject: [PATCH] osdmaptool: print useful error instead of crashing if osdmap is corrupt --- src/osd/osd_types.h | 3 ++- src/osdmaptool.cc | 11 +++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/osd/osd_types.h b/src/osd/osd_types.h index 8e2caca85f261..4b1d8d5e1511d 100644 --- a/src/osd/osd_types.h +++ b/src/osd/osd_types.h @@ -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); diff --git a/src/osdmaptool.cc b/src/osdmaptool.cc index 173122ac084de..f6e65d050fbdf 100644 --- a/src/osdmaptool.cc +++ b/src/osdmaptool.cc @@ -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) { -- 2.39.5