You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TL;DR: FATFS_stat & FATFS_readdir of the file system interface make illegal memory accesses to a character array never allocated.
When the File System Service is configured to use FatFS, the SYS_FS_FileStat interface attempts an illegal memory access that causes a bus fault (specifically an imprecise bus error). This occurs due to char* lfname of the SYS_FS_FSTAT struct is not used according to documentation, but the sys_fs_fat_interface.c dereferences this uninitialized pointer and assigns a value to a random location. The offending code snippet is provided below. I would recommend setting the pointer to NULL instead fileStat->lfname = NULL as an easy fix.
int FATFS_stat (
const char* path, /* Pointer to the file path */
uintptr_t fileInfo /* Pointer to file information to return */
)
{
FRESULT res;
FILINFO *finfo = (FILINFO *)fileInfo;
res = f_stat((const TCHAR *)path, finfo);
if (finfo != NULL)
{
SYS_FS_FSTAT *fileStat = (SYS_FS_FSTAT *)fileInfo;
if ((res == FR_OK) && (fileStat->lfname != NULL))
{
/* Use fileStat->fname instead */
fileStat->lfname[0] = '\0';
}
}
return ((int)res);
}
I see the FATFS_readdir() function in the interface makes similar illegal access as well.
For replication, one should test with calling on a directory or file that already exists. I am using a SAME53 that had this code generated using the latest MCC.
The text was updated successfully, but these errors were encountered:
TL;DR: FATFS_stat & FATFS_readdir of the file system interface make illegal memory accesses to a character array never allocated.
When the File System Service is configured to use FatFS, the SYS_FS_FileStat interface attempts an illegal memory access that causes a bus fault (specifically an imprecise bus error). This occurs due to
char* lfname
of the SYS_FS_FSTAT struct is not used according to documentation, but the sys_fs_fat_interface.c dereferences this uninitialized pointer and assigns a value to a random location. The offending code snippet is provided below. I would recommend setting the pointer to NULL insteadfileStat->lfname = NULL
as an easy fix.I see the FATFS_readdir() function in the interface makes similar illegal access as well.
For replication, one should test with calling on a directory or file that already exists. I am using a SAME53 that had this code generated using the latest MCC.
The text was updated successfully, but these errors were encountered: