summaryrefslogtreecommitdiffstats
path: root/src/file_ext.c
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2009-01-18 14:19:26 +0100
committerChristophe Grenier <grenier@cgsecurity.org>2009-01-18 14:19:26 +0100
commite333a67ac7d1f671f0ab14c9bb01e25c73c1917c (patch)
treef313a1b4366aa3cb803ba896bcea1871d61dbb13 /src/file_ext.c
parentaf4972541b2b0ce59ee423d6bf0a52f5eee0ad46 (diff)
file_ext.c: remove a dependency to ext2.c
Diffstat (limited to 'src/file_ext.c')
-rw-r--r--src/file_ext.c29
1 files changed, 21 insertions, 8 deletions
diff --git a/src/file_ext.c b/src/file_ext.c
index 77dca3f..3f9502c 100644
--- a/src/file_ext.c
+++ b/src/file_ext.c
@@ -54,12 +54,25 @@ static void register_header_check_ext2_sb(file_stat_t *file_stat)
static int header_check_ext2_sb(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new)
{
- if(recover_EXT2(NULL,(const struct ext2_super_block *)buffer,NULL,0,0)==0)
- {
- reset_file_recovery(file_recovery_new);
- file_recovery_new->extension=file_hint_ext2_sb.extension;
- return 1;
- }
- return 0;
+ const struct ext2_super_block *sb=(const struct ext2_super_block *)buffer;
+ if(le16(sb->s_magic)!=EXT2_SUPER_MAGIC)
+ return 0;
+ if (le32(sb->s_free_blocks_count) >= le32(sb->s_blocks_count))
+ return 0;
+ if (le32(sb->s_free_inodes_count) >= le32(sb->s_inodes_count))
+ return 0;
+ if (le16(sb->s_errors)!=0 &&
+ (le16(sb->s_errors) != EXT2_ERRORS_CONTINUE) &&
+ (le16(sb->s_errors) != EXT2_ERRORS_RO) &&
+ (le16(sb->s_errors) != EXT2_ERRORS_PANIC))
+ return 0;
+ if ((le16(sb->s_state) & ~(EXT2_VALID_FS | EXT2_ERROR_FS))!=0)
+ return 0;
+ if (le32(sb->s_blocks_count) == 0) /* reject empty filesystem */
+ return 0;
+ if(le32(sb->s_log_block_size)>2) /* block size max = 4096, can be 8192 on alpha */
+ return 0;
+ reset_file_recovery(file_recovery_new);
+ file_recovery_new->extension=file_hint_ext2_sb.extension;
+ return 1;
}
-