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
The following commit(s) were added to refs/heads/master by this push:
new 40d9ef45feb fs/vfs: Return the length that the file system gives from
readlink().
40d9ef45feb is described below
commit 40d9ef45feb9e793bed51d9499ec6147df04013b
Author: Marco Casaroli <[email protected]>
AuthorDate: Sun Oct 11 19:38:52 2026 +0200
fs/vfs: Return the length that the file system gives from readlink().
readlink() of a path in a mounted file system returned strlen() of the
buffer. The readlink method of a file system, like readlink(), returns
the number of bytes it placed and does not add a null byte, so
strlen() read past the target into old buffer contents. readlink() now
returns the length that the file system gives.
Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Marco Casaroli <[email protected]>
---
fs/vfs/fs_readlink.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/fs/vfs/fs_readlink.c b/fs/vfs/fs_readlink.c
index 51f09ad18cc..2c613995c85 100644
--- a/fs/vfs/fs_readlink.c
+++ b/fs/vfs/fs_readlink.c
@@ -26,6 +26,7 @@
#include <nuttx/config.h>
+#include <sys/param.h>
#include <sys/types.h>
#include <stdbool.h>
#include <string.h>
@@ -71,6 +72,7 @@ ssize_t readlink(FAR const char *path, FAR char *buf, size_t
bufsize)
{
struct inode_search_s desc;
FAR struct inode *node;
+ ssize_t nread;
int ret;
DEBUGASSERT(path != NULL && buf != NULL && bufsize > 0);
@@ -102,9 +104,11 @@ ssize_t readlink(FAR const char *path, FAR char *buf,
size_t bufsize)
{
if (node->u.i_mops && node->u.i_mops->readlink)
{
- ret = node->u.i_mops->readlink(node, desc.relpath, buf, bufsize);
- if (ret < 0)
+ nread = node->u.i_mops->readlink(node, desc.relpath, buf,
+ bufsize);
+ if (nread < 0)
{
+ ret = nread;
goto errout_with_inode;
}
}
@@ -137,14 +141,15 @@ ssize_t readlink(FAR const char *path, FAR char *buf,
size_t bufsize)
/* Copy the link target path to the user-provided buffer. */
- strlcpy(buf, node->u.i_link, bufsize);
+ nread = strlcpy(buf, node->u.i_link, bufsize);
+ nread = MIN(nread, bufsize);
}
/* Release our reference on the inode and return the length */
inode_release(node);
inode_search_release(&desc);
- return strlen(buf);
+ return nread;
errout_with_inode:
inode_release(node);