From 5a742b94f01a279c370fb682d03ebdd0d750c6e4 Mon Sep 17 00:00:00 2001 From: Moinak Ghosh Date: Mon, 3 Nov 2014 23:32:12 +0530 Subject: [PATCH] Add checksum verification of metadata chunks. --- meta_stream.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/meta_stream.c b/meta_stream.c index 1ed0ce6..61f9a78 100644 --- a/meta_stream.c +++ b/meta_stream.c @@ -327,6 +327,7 @@ decompress_data(meta_ctx_t *mctx) /* * Verify Header CRC32 in non-crypto mode. */ + deserialize_checksum(checksum, cbuf + 25, pctx->cksum_bytes); crc1 = U32_P(cbuf + 25 + CKSUM_MAX); memset(cbuf + 25 + CKSUM_MAX, 0, CRC32_SIZE); crc2 = lzma_crc32(cbuf, METADATA_HDR_SZ, 0); @@ -361,6 +362,18 @@ decompress_data(meta_ctx_t *mctx) } memcpy(ubuf, cseg, dstlen); } + + /* + * Now verify normal checksum if not using encryption. + */ + if (!pctx->encrypt_type) { + compute_checksum(mctx->checksum, pctx->cksum, ubuf, dstlen, 0, 1); + if (memcmp(checksum, mctx->checksum, pctx->cksum_bytes) != 0) { + log_msg(LOG_ERR, 0, "Metadata chunk %d, Checksum verification failed", + mctx->id); + return (0); + } + } mctx->topos = 0; mctx->tosize = dstlen; return (1);