summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2015-04-09 12:48:38 +0200
committerChristophe Grenier <grenier@cgsecurity.org>2015-04-09 12:48:38 +0200
commit1f42c92ca563b598d2df84834a4a7839e65cfd34 (patch)
tree5acbfd3885d28236a69701d70c5fb3e9a9a93dce
parent52190cd076ba6b47d59eeaf888a5f0029bd8d3a1 (diff)
Check that disk sector_size is 512 bytes at least
-rw-r--r--src/parthumax.c5
-rw-r--r--src/parti386.c8
-rw-r--r--src/partsun.c5
3 files changed, 14 insertions, 4 deletions
diff --git a/src/parthumax.c b/src/parthumax.c
index d140cb5..58ea514 100644
--- a/src/parthumax.c
+++ b/src/parthumax.c
@@ -105,7 +105,10 @@ static list_part_t *read_part_humax(disk_t *disk_car, const int verbose, const i
struct humaxlabel *humaxlabel;
list_part_t *new_list_part=NULL;
uint32_t *p32;
- unsigned char *buffer=(unsigned char *)MALLOC(disk_car->sector_size);
+ unsigned char *buffer;
+ if(disk_car->sector_size < DEFAULT_SECTOR_SIZE)
+ return NULL;
+ buffer=(unsigned char *)MALLOC(disk_car->sector_size);
screen_buffer_reset();
humaxlabel=(struct humaxlabel*)buffer;
p32=(uint32_t*)buffer;
diff --git a/src/parti386.c b/src/parti386.c
index eb410f7..c9fb231 100644
--- a/src/parti386.c
+++ b/src/parti386.c
@@ -663,8 +663,12 @@ static int write_part_i386(disk_t *disk_car, const list_part_t *list_part, const
static int write_mbr_i386(disk_t *disk_car, const list_part_t *list_part, const int ro, const int verbose)
{
const list_part_t *element;
- unsigned char *buffer=(unsigned char *)MALLOC(disk_car->sector_size);
- unsigned char *buffer_org=(unsigned char *)MALLOC(disk_car->sector_size);
+ unsigned char *buffer;
+ unsigned char *buffer_org;
+ if(disk_car->sector_size < DEFAULT_SECTOR_SIZE)
+ return 0;
+ buffer=(unsigned char *)MALLOC(disk_car->sector_size);
+ buffer_org=(unsigned char *)MALLOC(disk_car->sector_size);
if(verbose>0)
{
log_trace("\nwrite_mbr_i386: starting...\n");
diff --git a/src/partsun.c b/src/partsun.c
index 0c749e7..15afebf 100644
--- a/src/partsun.c
+++ b/src/partsun.c
@@ -132,7 +132,10 @@ static list_part_t *read_part_sun(disk_t *disk_car, const int verbose, const int
unsigned int i;
sun_disklabel *sunlabel;
list_part_t *new_list_part=NULL;
- unsigned char *buffer=(unsigned char *)MALLOC(disk_car->sector_size);
+ unsigned char *buffer;
+ if(disk_car->sector_size < DEFAULT_SECTOR_SIZE)
+ return NULL;
+ buffer=(unsigned char *)MALLOC(disk_car->sector_size);
screen_buffer_reset();
sunlabel=(sun_disklabel*)buffer;
if(disk_car->pread(disk_car, buffer, DEFAULT_SECTOR_SIZE, (uint64_t)0) != DEFAULT_SECTOR_SIZE)