This is an automated email from the ASF dual-hosted git repository. GUIDINGLI pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit e6235d364cf7f40b6f7487eeb1f9297f3bfa2eaf Author: zhengyu16 <[email protected]> AuthorDate: Thu Nov 12 13:08:43 2026 +0800 fs/vfs: do not NUL-terminate readlink() output readlink() copies the target of a pseudo file system link with strlcpy(), which ends the copy with a NUL. When the target does not fit, the last byte of the buffer is that NUL instead of the next byte of the target, although readlink() returns bufsize. POSIX says the result is not NUL-terminated. Copy at most bufsize bytes instead. Signed-off-by: zhengyu16 <[email protected]> Signed-off-by: jingfei <[email protected]> --- fs/vfs/fs_readlink.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/vfs/fs_readlink.c b/fs/vfs/fs_readlink.c index 2c613995c85..87c72d6bd20 100644 --- a/fs/vfs/fs_readlink.c +++ b/fs/vfs/fs_readlink.c @@ -139,10 +139,10 @@ ssize_t readlink(FAR const char *path, FAR char *buf, size_t bufsize) goto errout_with_inode; } - /* Copy the link target path to the user-provided buffer. */ + /* readlink() does not NUL-terminate: copy at most bufsize bytes */ - nread = strlcpy(buf, node->u.i_link, bufsize); - nread = MIN(nread, bufsize); + nread = MIN(strlen(node->u.i_link), bufsize); + memcpy(buf, node->u.i_link, nread); } /* Release our reference on the inode and return the length */
