coap-server.c: avoid fopen on NULL pointer in read_file_mem

As the behavior for calling fopen() on a NULL pointer is undefined in
ISO C99, a check is added before passing the file name to fopen().

This fixes CID 1495723.
This commit is contained in:
Olaf Bergmann committed 2020-06-19 16:01:29 +02:00
1 parent 1fded5dace
commit e413fd545b
1 file changed
+2 -2
+2 -2
View File
@@ -735,12 +735,12 @@ verify_cn_callback(const char *cn,
}
static uint8_t *read_file_mem(const char* file, size_t *length) {
FILE *f = fopen(file, "r");
FILE *f;
uint8_t *buf;
struct stat statbuf;
*length = 0;
if (!f)
if (!file || !(f = fopen(file, "r")))
return NULL;
if (fstat(fileno(f), &statbuf) == -1) {