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 <dongjiuzhu1@xiaomi.com>
This commit is contained in:
dongjiuzhu1
2025-04-17 20:48:27 +08:00
committed by Alan C. Assis
parent 8f41613374
commit e399c93cf3
+1 -1
View File
@@ -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;