Skip to content

Commit 37b5442

Browse files
author
Oren Cohen
committed
Fix overflow in disk_get_sector_size()
1 parent 06dffda commit 37b5442

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

features/storage/filesystem/fat/FATFileSystem.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,12 @@ void ff_memfree(void *p)
166166
}
167167

168168
// Implementation of diskio functions (see ChaN/diskio.h)
169-
static WORD disk_get_sector_size(BYTE pdrv)
169+
static DWORD disk_get_sector_size(BYTE pdrv)
170170
{
171-
WORD ssize = _ffs[pdrv]->get_erase_size();
171+
bd_size_t sector_size = _ffs[pdrv]->get_erase_size();
172+
MBED_ASSERT(sector_size <= DWORD(-1));
173+
174+
DWORD ssize = sector_size;
172175
if (ssize < 512) {
173176
ssize = 512;
174177
}
@@ -248,7 +251,7 @@ DRESULT disk_ioctl(BYTE pdrv, BYTE cmd, void *buff)
248251
if (_ffs[pdrv] == NULL) {
249252
return RES_NOTRDY;
250253
} else {
251-
*((WORD*)buff) = disk_get_sector_size(pdrv);
254+
*((DWORD*)buff) = disk_get_sector_size(pdrv);
252255
return RES_OK;
253256
}
254257
case GET_BLOCK_SIZE:

0 commit comments

Comments
 (0)