mirror of
https://github.com/cesanta/mongoose.git
synced 2024-12-27 06:51:04 +08:00
Check for calloc() failure in filesystem code
This commit is contained in:
parent
4593332204
commit
f015a8686e
18
mongoose.c
18
mongoose.c
@ -788,12 +788,13 @@ static void *ff_open(const char *path, int flags) {
|
||||
unsigned char mode = FA_READ;
|
||||
if (flags & MG_FS_WRITE) mode |= FA_WRITE | FA_OPEN_ALWAYS | FA_OPEN_APPEND;
|
||||
if (f_open(&f, path, mode) == 0) {
|
||||
FIL *fp = calloc(1, sizeof(*fp));
|
||||
memcpy(fp, &f, sizeof(*fp));
|
||||
return fp;
|
||||
} else {
|
||||
return NULL;
|
||||
FIL *fp;
|
||||
if ((fp = calloc(1, sizeof(*fp))) != NULL) {
|
||||
memcpy(fp, &f, sizeof(*fp));
|
||||
return fp;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void ff_close(void *fp) {
|
||||
@ -913,9 +914,10 @@ static void *packed_open(const char *path, int flags) {
|
||||
struct packed_file *fp = NULL;
|
||||
if (data == NULL) return NULL;
|
||||
if (flags & MG_FS_WRITE) return NULL;
|
||||
fp = (struct packed_file *) calloc(1, sizeof(*fp));
|
||||
fp->size = size;
|
||||
fp->data = data;
|
||||
if ((fp = (struct packed_file *) calloc(1, sizeof(*fp))) != NULL) {
|
||||
fp->size = size;
|
||||
fp->data = data;
|
||||
}
|
||||
return (void *) fp;
|
||||
}
|
||||
|
||||
|
11
src/fs_fat.c
11
src/fs_fat.c
@ -73,12 +73,13 @@ static void *ff_open(const char *path, int flags) {
|
||||
unsigned char mode = FA_READ;
|
||||
if (flags & MG_FS_WRITE) mode |= FA_WRITE | FA_OPEN_ALWAYS | FA_OPEN_APPEND;
|
||||
if (f_open(&f, path, mode) == 0) {
|
||||
FIL *fp = calloc(1, sizeof(*fp));
|
||||
memcpy(fp, &f, sizeof(*fp));
|
||||
return fp;
|
||||
} else {
|
||||
return NULL;
|
||||
FIL *fp;
|
||||
if ((fp = calloc(1, sizeof(*fp))) != NULL) {
|
||||
memcpy(fp, &f, sizeof(*fp));
|
||||
return fp;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void ff_close(void *fp) {
|
||||
|
@ -67,9 +67,10 @@ static void *packed_open(const char *path, int flags) {
|
||||
struct packed_file *fp = NULL;
|
||||
if (data == NULL) return NULL;
|
||||
if (flags & MG_FS_WRITE) return NULL;
|
||||
fp = (struct packed_file *) calloc(1, sizeof(*fp));
|
||||
fp->size = size;
|
||||
fp->data = data;
|
||||
if ((fp = (struct packed_file *) calloc(1, sizeof(*fp))) != NULL) {
|
||||
fp->size = size;
|
||||
fp->data = data;
|
||||
}
|
||||
return (void *) fp;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user