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)
|
202 | 202 | bool |
203 | 203 | ext2_super_block::IsValid() |
204 | 204 | { |
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) |
207 | 211 | 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 | } |
208 | 220 | |
209 | 221 | return true; |
210 | 222 | } |
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 {
|
194 | 194 | #define EXT2_STATE_INVALID 0x02 |
195 | 195 | |
196 | 196 | #define EXT2_BLOCK_GROUP_NORMAL_SIZE 32 |
| 197 | #define EXT2_BLOCK_GROUP_64BIT_SIZE 64 |
197 | 198 | |
198 | 199 | // block group flags |
199 | 200 | #define EXT2_BLOCK_GROUP_INODE_UNINIT 0x1 |