diff options
author | Christian Mauderer <christian.mauderer@embedded-brains.de> | 2022-04-04 15:17:56 +0200 |
---|---|---|
committer | Christian Mauderer <christian.mauderer@embedded-brains.de> | 2022-04-07 10:37:23 +0200 |
commit | 43119193ef0f3fef6bc01a391ccda8a97cfc149c (patch) | |
tree | 0e45eb386c55140e658824a2f446ac9657942b51 /cpukit/libfs/src/imfs | |
parent | bsp/stm32h7: update FMC configuration for SRAM and SDRAM usage (diff) | |
download | rtems-43119193ef0f3fef6bc01a391ccda8a97cfc149c.tar.bz2 |
imfs: Fix index underrun when extending empty file
Currently the following sequence causes a endless loop when extending an
IMFS file:
- Create a file with zero length and close it.
- Make sure nearly no allocatable memory is left.
- Open the file and write enough data into it that more than the
remaining memory will be used.
In that case when extending the IMFS file, the file currently need zero
blocks. If allocating enough new blocks fails, the already allocated new
blocks will be freed again.
The comparison of block>=old_blocks that has been used prior to this
patch compared two unsigned numbers. If old_blocks was zero, the
comparison of these two numbers always evaluated to true.
This patch frees the last block in a separate step to avoid this
problem.
Fixes #4639
Diffstat (limited to 'cpukit/libfs/src/imfs')
-rw-r--r-- | cpukit/libfs/src/imfs/imfs_memfile.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/cpukit/libfs/src/imfs/imfs_memfile.c b/cpukit/libfs/src/imfs/imfs_memfile.c index 23c7192717..769a570ecf 100644 --- a/cpukit/libfs/src/imfs/imfs_memfile.c +++ b/cpukit/libfs/src/imfs/imfs_memfile.c @@ -208,9 +208,10 @@ static int IMFS_memfile_extend( offset = 0; } } else { - for ( ; block>=old_blocks ; block-- ) { + for ( ; block>old_blocks ; block-- ) { IMFS_memfile_remove_block( memfile, block ); } + IMFS_memfile_remove_block( memfile, old_blocks ); rtems_set_errno_and_return_minus_one( ENOSPC ); } } |