From ed3c55569d903064a6578c5b44a2be4dad3899fe Mon Sep 17 00:00:00 2001 From: Acts1631 Date: Thu, 12 Nov 2026 19:24:21 -0500 Subject: [PATCH] reject oversized readlink targets Symlink containment checked the complete server target, but readlink silently truncated it to the FUSE output buffer. A target ending in "..x" beyond the boundary could therefore be exposed as ".." after it had passed containment. Preserve containment error behavior, reject otherwise-safe targets that do not fit, and copy only the exact validated target. --- sshfs.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/sshfs.c b/sshfs.c index 4cdf1223..20e27eab 100644 --- a/sshfs.c +++ b/sshfs.c @@ -2294,19 +2294,22 @@ static int sshfs_readlink(const char *path, char *linkbuf, size_t size) err = -EIO; if(buf_get_uint32(&name, &count) != -1 && count == 1 && buf_get_string(&name, &link) != -1) { + size_t linklen; + if (sshfs.transform_symlinks) transform_symlink(path, &link); + linklen = strlen(link); if (sshfs.contain_symlinks && !symlink_target_is_contained(link)) { - free(link); - buf_free(&name); - buf_free(&buf); - return -EPERM; + err = -EPERM; + /* Truncation can change a component such as "..x" to "..". */ + } else if (linklen >= size) { + err = -ENAMETOOLONG; + } else { + memcpy(linkbuf, link, linklen + 1); + err = 0; } - strncpy(linkbuf, link, size - 1); - linkbuf[size - 1] = '\0'; free(link); - err = 0; } buf_free(&name); }