Ticket #13401: 0002-ext2-Volume-check-some-more-values-for-ext2_super_bl.patch

File 0002-ext2-Volume-check-some-more-values-for-ext2_super_bl.patch, 1.9 KB (added by wangxindsb, 8 years ago)

Complete the TODO: check some more values! in the haiku/src/add-ons/kernel/file_systems/ext2/Volume.cpp

  • src/add-ons/kernel/file_systems/ext2/Volume.cpp

    From 1851c9d65c997d9a4e7409e38c22849cc37f5b60 Mon Sep 17 00:00:00 2001
    From: wangxindsb <wangxindsb.gmail.com>
    Date: Tue, 28 Mar 2017 08:34:54 -0700
    Subject: [PATCH 2/2] ext2 Volume, check some more values for ext2_super_block
    
    ---
     src/add-ons/kernel/file_systems/ext2/Volume.cpp | 16 ++++++++++++++--
     src/add-ons/kernel/file_systems/ext2/ext2.h     |  1 +
     2 files changed, 15 insertions(+), 2 deletions(-)
    
    diff --git a/src/add-ons/kernel/file_systems/ext2/Volume.cpp b/src/add-ons/kernel/file_systems/ext2/Volume.cpp
    index 629cec7..3b59251 100644
    a b DeviceOpener::GetSize(off_t* _size, uint32* _blockSize)  
    202202bool
    203203ext2_super_block::IsValid()
    204204{
    205     // TODO: check some more values!
    206     if (Magic() != (uint32)EXT2_SUPER_BLOCK_MAGIC)
     205    if (Magic() != (uint32)EXT2_SUPER_BLOCK_MAGIC
     206            || BlockShift() > 16
     207            || BlocksPerGroup() != (1UL << BlockShift()) * 8
     208            || InodeSize() > (1UL << BlockShift())
     209            || RevisionLevel() > EXT2_MAX_REVISION
     210            || ReservedGDTBlocks() > (1UL << BlockShift()) / 4)
    207211        return false;
     212    if (Has64bitFeature()) {
     213        if (GroupDescriptorSize() > EXT2_BLOCK_GROUP_64BIT_SIZE  || GroupDescriptorSize() < EXT2_BLOCK_GROUP_NORMAL_SIZE)
     214            return false;
     215    }
     216    else {
     217        if (GroupDescriptorSize() != EXT2_BLOCK_GROUP_NORMAL_SIZE)
     218            return false;
     219    }
    208220   
    209221    return true;
    210222}
  • src/add-ons/kernel/file_systems/ext2/ext2.h

    diff --git a/src/add-ons/kernel/file_systems/ext2/ext2.h b/src/add-ons/kernel/file_systems/ext2/ext2.h
    index 2bc5f7f..2e7479e 100644
    a b struct ext2_super_block {  
    194194#define EXT2_STATE_INVALID                      0x02
    195195
    196196#define EXT2_BLOCK_GROUP_NORMAL_SIZE            32
     197#define EXT2_BLOCK_GROUP_64BIT_SIZE             64
    197198
    198199// block group flags
    199200#define EXT2_BLOCK_GROUP_INODE_UNINIT   0x1