mirror of
https://github.com/obgm/libcoap.git
synced 2026-11-08 10:32:53 +03:00
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:
1 parent
1fded5dace
commit
e413fd545b
1 file changed
+2
-2
@@ -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) {
|
||||
|
||||
Reference in new issue
Block a user