]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
osd/OSDMap: verify CRC on decode
authorSage Weil <sage@redhat.com>
Thu, 21 Aug 2014 17:43:05 +0000 (10:43 -0700)
committerSage Weil <sage@redhat.com>
Mon, 10 Nov 2014 22:20:25 +0000 (14:20 -0800)
Signed-off-by: Sage Weil <sage@redhat.com>
src/osd/OSDMap.cc

index a1131eda33efc59378134a4a8c3eb3b4ddac3927..864d5542f8af1299ff3ca51b6651cc5fb6bae9e6 100644 (file)
@@ -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();
 }