From f98687bef7c34588a84a3c50143b9455067ff496 Mon Sep 17 00:00:00 2001 From: QiaoChong Date: Thu, 25 Apr 2019 13:32:57 +0800 Subject: [PATCH] ext2fs: ext2fs bh reallocated if size is not enough for new inode. Change-Id: I128cb157e263bc4c5180a1f7f70a3c92e2c7a166 Signed-off-by: QiaoChong --- pmon/fs/ext2fs.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pmon/fs/ext2fs.c b/pmon/fs/ext2fs.c index cacce288..e183e373 100644 --- a/pmon/fs/ext2fs.c +++ b/pmon/fs/ext2fs.c @@ -266,7 +266,7 @@ static int ext2_load_linux(int fd,int index, const unsigned char *path) struct ext2_inode *ext2_raw_inode; ext2_dirent *de; unsigned char *bh; - int i; + int i, bh_size; unsigned int inode; int find = 1; unsigned char s[EXT2_NAME_LEN]; @@ -277,6 +277,7 @@ static int ext2_load_linux(int fd,int index, const unsigned char *path) showdir = 0; lookupdir = 0; bh = 0; + bh_size = 0; if(read_super_block(fd,index)) return -1; @@ -300,8 +301,12 @@ static int ext2_load_linux(int fd,int index, const unsigned char *path) printf("load EXT2_ROOT_INO error"); return -1; } - if(!bh) + if (!bh || bh_size < sb_block_size + ext2_raw_inode->i_size) + { + if(bh) free(bh); bh = (unsigned char *)malloc(sb_block_size + ext2_raw_inode->i_size); + bh_size = sb_block_size + ext2_raw_inode->i_size; + } if(!bh) { printf("Error in allocting memory for file content!\n");