From abf70cdcc14122ec7fddfcf266771b54c67839aa Mon Sep 17 00:00:00 2001 From: Marcus Huewe Date: Thu, 12 May 2016 15:35:44 -0400 Subject: [PATCH] libext2fs: fix key extension in undo_write_tdb Support key extension if the tdb_data_size is an arbitrary integer multiple of the channel's block size. Before, key extension was only possible if the tdb_data_size and the channel's block size were equal. Note: a key, whose data is the result of a short read, will be extended if the tdb_data_size and the channel's block size are equal (that's what the old code did) (if tdb_data_size is an arbitrary integer multiple (> 1) of the channel's block size, the key might be extended as well (depending on the keysize)). Signed-off-by: Marcus Huewe Signed-off-by: Theodore Ts'o --- lib/ext2fs/undo_io.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/ext2fs/undo_io.c b/lib/ext2fs/undo_io.c index 4cc1e9d..cb8eaa8 100644 --- a/lib/ext2fs/undo_io.c +++ b/lib/ext2fs/undo_io.c @@ -417,11 +417,11 @@ static errcode_t undo_write_tdb(io_channel channel, keysz = 0; } if (key != NULL && - ext2fs_le64_to_cpu(key->fsblk) + - ((keysz + data->tdb_data_size - 1) / - data->tdb_data_size) == backing_blk_num && + (ext2fs_le64_to_cpu(key->fsblk) * channel->block_size + + channel->block_size - 1 + + keysz) / channel->block_size == backing_blk_num && E2UNDO_MAX_EXTENT_BLOCKS * data->tdb_data_size > - keysz + sz) { + keysz + data_size) { blk_crc = ext2fs_le32_to_cpu(key->blk_crc); blk_crc = ext2fs_crc32c_le(blk_crc, read_ptr, data_size); key->blk_crc = ext2fs_cpu_to_le32(blk_crc); -- 1.8.3.1