Changeset 051778e in rtems
- Timestamp:
-
04/04/22 13:17:56
(14 months ago)
- Author:
- Christian Mauderer <christian.mauderer@…>
- Branches:
- 4.11
- Parents:
- 63c6b06f
- git-author:
- Christian Mauderer <christian.mauderer@…> (04/04/22 13:17:56)
- git-committer:
- Christian Mauderer <christian.mauderer@…> (04/07/22 08:45:12)
- Message:
-
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.
Note: This patch is a backport of
43119193ef0f3fef6bc01a391ccda8a97cfc149c from RTEMS master. It only
contains the bugfix. Adding a test case has been skipped because that
part of the patch didn't apply without problems and is not really
relevant for fixing the bug.
Fixes #2353
-
File:
-
Legend:
- Unmodified
- Added
- Removed
-
r63c6b06f
|
r051778e
|
|
189 | 189 | } |
190 | 190 | } else { |
191 | | for ( ; block>=old_blocks ; block-- ) { |
| 191 | for ( ; block>old_blocks ; block-- ) { |
192 | 192 | IMFS_memfile_remove_block( memfile, block ); |
193 | 193 | } |
| 194 | IMFS_memfile_remove_block( memfile, old_blocks ); |
194 | 195 | rtems_set_errno_and_return_minus_one( ENOSPC ); |
195 | 196 | } |