ref: 0225f4b6bbff4f2517a53b11ddcbeb57d7193f21
parent: 8ab7728d26e22d0d6310d8fc4b269a9625764c60
author: ngkaho1234 <ngkaho1234@gmail.com>
date: Sat Nov 14 05:55:45 EST 2015
ext4_mkfs: fix SIGSEGV caused by inaccurate memory allocation size.
--- a/lwext4/ext4_mkfs.c
+++ b/lwext4/ext4_mkfs.c
@@ -184,8 +184,8 @@
if (!aux_info->sb)
return ENOMEM;
- aux_info->bg_desc = calloc(sizeof(struct ext4_bgroup),
- aux_info->bg_desc_blocks);
+ aux_info->bg_desc = calloc(aux_info->groups,
+ sizeof(struct ext4_bgroup));
if (!aux_info->bg_desc)
return ENOMEM;
@@ -197,7 +197,7 @@
{
if (aux_info->sb)
free(aux_info->sb);
- if (aux_info->sb)
+ if (aux_info->bg_desc)
free(aux_info->bg_desc);
}
@@ -317,7 +317,8 @@
+ i * info->blocks_per_group);
aux_info->sb->block_group_index = i;
- r = ext4_block_writebytes(bd, offset, aux_info->sb, 1024);
+ r = ext4_block_writebytes(bd, offset, aux_info->sb,
+ sizeof(struct ext4_sblock));
if (r != EOK)
return r;
}
@@ -325,7 +326,8 @@
/* write out the primary superblock */
aux_info->sb->block_group_index = 0;
- return ext4_block_writebytes(bd, 1024, aux_info->sb, 1024);
+ return ext4_block_writebytes(bd, 1024, aux_info->sb,
+ sizeof(struct ext4_sblock));
}
@@ -358,6 +360,7 @@
int ext4_mkfs(struct ext4_blockdev *bd, struct ext4_mkfs_info *info)
{
int r;
+ struct fs_aux_info aux_info;
r = ext4_block_init(bd);
if (r != EOK)
return r;
@@ -421,7 +424,6 @@
!info->no_journal ? "yes" : "no");
ext4_dbg(DEBUG_MKFS, DBG_NONE "Label: %s\n", info->label);
- struct fs_aux_info aux_info;
memset(&aux_info, 0, sizeof(struct fs_aux_info));
r = create_fs_aux_info(&aux_info, info);