Changeset 051778e in rtems


Ignore:
Timestamp:
04/04/22 13:17:56 (2 years 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:
1 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libfs/src/imfs/imfs_memfile.c

    r63c6b06f r051778e  
    189189       }
    190190    } else {
    191        for ( ; block>=old_blocks ; block-- ) {
     191       for ( ; block>old_blocks ; block-- ) {
    192192         IMFS_memfile_remove_block( memfile, block );
    193193       }
     194       IMFS_memfile_remove_block( memfile, old_blocks );
    194195       rtems_set_errno_and_return_minus_one( ENOSPC );
    195196    }
Note: See TracChangeset for help on using the changeset viewer.