Merge pull request #15431 from alrvid/patch-1

Handle negative values passed to close()
pull/15435/head
Martin Kojtal 2023-07-03 16:08:17 +02:00 committed by GitHub
commit f9c0cd2a94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 0 deletions

View File

@ -656,6 +656,10 @@ extern "C" int PREFIX(_close)(FILEHANDLE fh)
#if !MBED_CONF_PLATFORM_STDIO_MINIMAL_CONSOLE_ONLY #if !MBED_CONF_PLATFORM_STDIO_MINIMAL_CONSOLE_ONLY
extern "C" int close(int fildes) extern "C" int close(int fildes)
{ {
if (fildes < 0) {
errno = EBADF;
return -1;
}
FileHandle *fhc = mbed_file_handle(fildes); FileHandle *fhc = mbed_file_handle(fildes);
filehandles[fildes] = NULL; filehandles[fildes] = NULL;
if (fhc == NULL) { if (fhc == NULL) {