This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit b88672c1c35e75d4e78c024b515710b94fb125b8 Author: zhengyu16 <[email protected]> AuthorDate: Tue Jan 13 14:58:17 2026 +0800 fs/rpmsgfs/rpmsgfs_server: check the buffer size in readlink The readlink handler stored rpmsg_get_tx_buffer_size() in a uint32_t, so a negative error turned into a huge size, and a buffer no larger than the message header made space - sizeof(*msg) wrap around. Either way readlink() could write past the end of the message. Reply with the error instead, or with -EINVAL when the buffer is too small. Signed-off-by: zhengyu16 <[email protected]> Signed-off-by: Bowen Wang <[email protected]> --- fs/rpmsgfs/rpmsgfs_server.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/fs/rpmsgfs/rpmsgfs_server.c b/fs/rpmsgfs/rpmsgfs_server.c index 40b1501d835..76c8533b24d 100644 --- a/fs/rpmsgfs/rpmsgfs_server.c +++ b/fs/rpmsgfs/rpmsgfs_server.c @@ -959,11 +959,29 @@ static int rpmsgfs_readlink_handler(FAR struct rpmsg_endpoint *ept, { FAR struct rpmsgfs_readlink_s *msg = data; ssize_t ret; - uint32_t space; + ssize_t space; space = rpmsg_get_tx_buffer_size(ept); + if (space < 0) + { + ret = space; + goto out; + } + + if (space <= sizeof(*msg)) + { + ret = -EINVAL; + goto out; + } + ret = readlink(msg->pathname, msg->pathname, space - sizeof(*msg)); - msg->header.result = ret < 0 ? -get_errno() : ret; + if (ret < 0) + { + ret = -get_errno(); + } + +out: + msg->header.result = ret; return rpmsg_send(ept, msg, sizeof(*msg) + (ret > 0 ? ret : 0)); }
