-
Notifications
You must be signed in to change notification settings - Fork 3k
Description
Several standard library functions and POSIX directory functions cause hard faults when given NULL arguments.
I know it's a bad idea to ever allow a NULL argument to be passed to these functions, but it seems to me it should fail gracefully instead of causing a hard fault.
The following calls result in a hard fault:
freopen("path/to/file", "mode", NULL)
fread(NULL, nsize, nitems, pFile)
fwrite(NULL, nsize, nitems, pFile)
closedir(NULL)
readdir(NULL)
rewinddir(NULL)
fseek(NULL, offset, whence)
If I remember right, I think calling fclose() twice on the same handle or calling closedir() twice on the same directory handle may cause a hard fault as well, but that may be more difficult to protect against.
Tested on FRDM-K64F with mbed OS 3 (and possibly mbed 2 as well, I can't remember).