Skip to content

Commit f9c0cd2

Browse files
authored
Merge pull request #15431 from alrvid/patch-1
Handle negative values passed to close()
2 parents 89c1705 + 56ca532 commit f9c0cd2

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

platform/source/mbed_retarget.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,10 @@ extern "C" int PREFIX(_close)(FILEHANDLE fh)
656656
#if !MBED_CONF_PLATFORM_STDIO_MINIMAL_CONSOLE_ONLY
657657
extern "C" int close(int fildes)
658658
{
659+
if (fildes < 0) {
660+
errno = EBADF;
661+
return -1;
662+
}
659663
FileHandle *fhc = mbed_file_handle(fildes);
660664
filehandles[fildes] = NULL;
661665
if (fhc == NULL) {

0 commit comments

Comments
 (0)