mirror of
https://github.com/apache/nuttx.git
synced 2026-08-28 21:00:44 +00:00
fs/inode: fix off-by-one error in _inode_checkpath NAME_MAX check
The _inode_checkpath function uses `namelen < NAME_MAX` to validate path segment lengths. When a filename is exactly NAME_MAX characters long and is followed by more path segments (e.g. /dir/), the loop exits with namelen == NAME_MAX before processing the '/' separator, causing a spurious ENAMETOOLONG error. Per POSIX, NAME_MAX is the maximum number of bytes in a filename not including the terminating null, so a filename of exactly NAME_MAX characters is valid. Change the condition to `namelen <= NAME_MAX` so the loop can process the trailing '/' separator and correctly reset namelen for the next path segment. Signed-off-by: wangxingxing <wangxingxing@xiaomi.com>
This commit is contained in:
parent
24d371c0fe
commit
ea4a4585cd
1 changed files with 1 additions and 1 deletions
|
|
@ -256,7 +256,7 @@ static int _inode_checkpath(const char *path)
|
|||
|
||||
/* Check each segment of the path */
|
||||
|
||||
while (*path != '\0' && namelen < NAME_MAX && pathlen < PATH_MAX)
|
||||
while (*path != '\0' && namelen <= NAME_MAX && pathlen < PATH_MAX)
|
||||
{
|
||||
if (*path == '/')
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue