From: Sage Weil Date: Thu, 21 Aug 2014 17:43:05 +0000 (-0700) Subject: osd/OSDMap: verify CRC on decode X-Git-Tag: v0.91~55^2~2^2~7 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=dafd3355345b4299f6c3c70b6b35876cdc2fb15c;p=ceph.git osd/OSDMap: verify CRC on decode Signed-off-by: Sage Weil --- diff --git a/src/osd/OSDMap.cc b/src/osd/OSDMap.cc index a1131eda33ef..864d5542f8af 100644 --- a/src/osd/OSDMap.cc +++ b/src/osd/OSDMap.cc @@ -654,6 +654,22 @@ void OSDMap::Incremental::decode(bufferlist::iterator& bl) } DECODE_FINISH(bl); // wrapper + + if (have_crc) { + // verify crc + uint32_t actual = crc_front.crc32c(-1); + if (tail_offset < bl.get_off()) { + bufferlist tail; + tail.substr_of(bl.get_bl(), tail_offset, bl.get_off() - tail_offset); + actual = tail.crc32c(actual); + } + if (inc_crc != actual) { + ostringstream ss; + ss << "bad crc, actual " << actual << " != expected " << inc_crc; + string s = ss.str(); + throw buffer::malformed_input(s.c_str()); + } + } } void OSDMap::Incremental::dump(Formatter *f) const @@ -2135,6 +2151,22 @@ void OSDMap::decode(bufferlist::iterator& bl) DECODE_FINISH(bl); // wrapper + if (tail_offset) { + // verify crc + uint32_t actual = crc_front.crc32c(-1); + if (tail_offset < bl.get_off()) { + bufferlist tail; + tail.substr_of(bl.get_bl(), tail_offset, bl.get_off() - tail_offset); + actual = tail.crc32c(actual); + } + if (crc != actual) { + ostringstream ss; + ss << "bad crc, actual " << actual << " != expected " << crc; + string s = ss.str(); + throw buffer::malformed_input(s.c_str()); + } + } + post_decode(); }