mirror of
https://gitlab.rtems.org/rtems/rtos/rtems.git
synced 2026-11-16 19:04:53 +08:00
This is where the fix came from. GCC's -fanalyzer reports:
rtems-rfs-buffer.c:274:24: warning: dereference of NULL 'buffer'
[CWE-476] [-Wanalyzer-null-dereference]
Mounting RFS with max-held-bufs=0 dereferences a NULL pointer on the first
buffer release.
rtems_rfs_buffer_handle_release evicts a held buffer when
(fs->release_count + fs->release_modified_count) >= fs->max_held_buffers
taking it from fs->release when release_count is the larger and from
fs->release_modified otherwise, then doing buffer->user = (void*)0 at
rtems-rfs-buffer.c:274 with no NULL test. rtems_chain_get_unprotected
returns NULL for an empty chain by design.
For max_held_buffers >= 1 the guard implies one of the counts is non-zero
and the branch selects the queue holding it, so the result is never NULL.
At zero the guard is 0 >= 0, true on the first release with both queues
still empty; 0 > 0 is false so the else branch runs; the count underflows
from zero; and the NULL reaches :274.
The value is a mount option and nothing range checked it: the parser used
strtoul straight into the local and rtems_rfs_fs_open assigned it
unchecked. Zero held buffers is not a meaningful configuration, so reject
it where it is parsed.
It mounts with max-held-bufs=0 and requires EINVAL, and with
max-held-bufs=1, which must succeed: the guard is >=, so at one the first
release sees 0 >= 1 and evicts nothing, which puts the boundary exactly
where the arithmetic says it is.
Also removes a stray printf("options=%s") from the option parsing loop.
It is debug output left in the mount path, so every RFS mount printed a
line per option to the console. It is in the function this commit already
changes, and it was polluting the test output above.
Signed-off-by: Samuel Price <thesamprice@gmail.com>
Assisted-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
libfs
This directory contains for the "file system" library. All supported file systems live under this tree.
Currently the supported file systems in this library are:
-
IMFS or In Memory File System
This is the only root file system on RTEMS at the moment. It supports files, directories, device nodes and mount points. It can also be configured to be the miniIMFS.
-
TFTP and FTP filesystem require networking support.
-
DEVFS or Device File system
-
DOSFS, a FAT 12/16/32 MSDOS compatible file system.
-
NFS Client, can mount NFS exported file systems.
-
PIPE, a pipe file system.
-
RFS, The RTEMS File System.
--Chris Johns and Joel Sherrill 17 Feb 2010