Check memsize against filesize before writing

This commit is contained in:
Olaf Rempel 2020-10-17 21:29:47 +02:00
parent 827b48d769
commit cd34f8c798
7 changed files with 12 additions and 12 deletions

View File

@ -209,7 +209,7 @@ static int butterfly_get_memtype(struct multiboot * p_mboot,
/* ************************************************************************* /* *************************************************************************
* butterfly_get_memsize * butterfly_get_memsize
* ************************************************************************* */ * ************************************************************************* */
static int butterfly_get_memsize(struct multiboot * p_mboot, static uint32_t butterfly_get_memsize(struct multiboot * p_mboot,
int memtype) int memtype)
{ {
bfly_privdata_t * p_priv = (bfly_privdata_t *)p_mboot->privdata; bfly_privdata_t * p_priv = (bfly_privdata_t *)p_mboot->privdata;

View File

@ -267,7 +267,7 @@ static int eprog_get_memtype(struct multiboot *mboot,
/* ************************************************************************* /* *************************************************************************
* eprog_get_memsize * eprog_get_memsize
* ************************************************************************* */ * ************************************************************************* */
static int eprog_get_memsize(struct multiboot *mboot, static uint32_t eprog_get_memsize(struct multiboot *mboot,
int memtype) int memtype)
{ {
struct eprog_privdata *p_prog = (struct eprog_privdata *)mboot->privdata; struct eprog_privdata *p_prog = (struct eprog_privdata *)mboot->privdata;

2
funk.c
View File

@ -279,7 +279,7 @@ static int funk_get_memtype(struct multiboot *mboot,
/* ************************************************************************* /* *************************************************************************
* funk_get_memsize * funk_get_memsize
* ************************************************************************* */ * ************************************************************************* */
static int funk_get_memsize(struct multiboot *mboot, static uint32_t funk_get_memsize(struct multiboot *mboot,
int memtype) int memtype)
{ {
struct funk_privdata *funk = (struct funk_privdata *)mboot->privdata; struct funk_privdata *funk = (struct funk_privdata *)mboot->privdata;

2
mpm.c
View File

@ -197,7 +197,7 @@ static int mpm_get_memtype(struct multiboot *mboot,
/* ************************************************************************* /* *************************************************************************
* mpm_get_memsize * mpm_get_memsize
* ************************************************************************* */ * ************************************************************************* */
static int mpm_get_memsize(struct multiboot *mboot, int memtype) static uint32_t mpm_get_memsize(struct multiboot *mboot, int memtype)
{ {
struct mpm_privdata *mpm = (struct mpm_privdata *)mboot->privdata; struct mpm_privdata *mpm = (struct mpm_privdata *)mboot->privdata;

View File

@ -374,8 +374,8 @@ int main(int argc, char *argv[])
break; break;
} }
int memsize = mboot->ops->get_memsize(mboot, action->memtype); uint32_t memsize = mboot->ops->get_memsize(mboot, action->memtype);
if (memsize == 0) if ((memsize == 0) || (memsize < dbuf->length))
{ {
fprintf(stderr, "invalid memsize: 0x%04x > 0x%04x\n", dbuf->length, memsize); fprintf(stderr, "invalid memsize: 0x%04x > 0x%04x\n", dbuf->length, memsize);
dbuf_free(dbuf); dbuf_free(dbuf);

View File

@ -21,7 +21,7 @@ struct multiboot_ops
void (* free)(struct multiboot *mboot); void (* free)(struct multiboot *mboot);
int (* get_memtype)(struct multiboot *mboot, const char *memname); int (* get_memtype)(struct multiboot *mboot, const char *memname);
int (* get_memsize)(struct multiboot *mboot, int memtype); uint32_t (* get_memsize)(struct multiboot *mboot, int memtype);
int (* open)(struct multiboot *mboot); int (* open)(struct multiboot *mboot);
int (* close)(struct multiboot *mboot); int (* close)(struct multiboot *mboot);

2
twi.c
View File

@ -592,7 +592,7 @@ static int twi_get_memtype(struct multiboot *mboot,
/* ************************************************************************* /* *************************************************************************
* twi_get_memsize * twi_get_memsize
* ************************************************************************* */ * ************************************************************************* */
static int twi_get_memsize(struct multiboot *mboot, static uint32_t twi_get_memsize(struct multiboot *mboot,
int memtype) int memtype)
{ {
struct twi_privdata *twi = (struct twi_privdata *)mboot->privdata; struct twi_privdata *twi = (struct twi_privdata *)mboot->privdata;