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