This is an automated email from the ASF dual-hosted git repository. acassis pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit e399c93cf3464b824b1656693de0d2b53038fd33 Author: dongjiuzhu1 <[email protected]> AuthorDate: Thu Apr 17 20:48:27 2025 +0800 fs/inode: Fix fd allocation succeeding when exceeding OPEN_MAX Before this fix, the check for OPEN_MAX was performed using orig_rows instead of the new row count after extension. This caused the check to pass even when the allocation would exceed OPEN_MAX limit. For example: - OPEN_MAX = 256 - CONFIG_NFILE_DESCRIPTORS_PER_BLOCK = 32 - orig_rows = 8 (8 * 32 = 256, at the limit) The old code checked: 32 * 8 > 256 (false, allows extension) The new code checks: 32 * (8 + 1) > 256 (true, correctly blocks) Without this fix, the system could allocate more file descriptors than OPEN_MAX allows, potentially causing memory corruption or exceeding system limits. This fix ensures the check evaluates the new total count (orig_rows + 1) before allowing the extension to proceed. Signed-off-by: dongjiuzhu1 <[email protected]> --- fs/inode/fs_files.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/inode/fs_files.c b/fs/inode/fs_files.c index bb1810e7aa0..6e16601bcf0 100644 --- a/fs/inode/fs_files.c +++ b/fs/inode/fs_files.c @@ -104,7 +104,7 @@ static int fdlist_extend(FAR struct fdlist *list, size_t row) return 0; } - if (CONFIG_NFILE_DESCRIPTORS_PER_BLOCK * orig_rows > OPEN_MAX) + if (CONFIG_NFILE_DESCRIPTORS_PER_BLOCK * (orig_rows + 1) > OPEN_MAX) { fdlist_dump(list); return -EMFILE;
